Changeset 70012 in webkit


Ignore:
Timestamp:
Oct 18, 2010 5:40:58 PM (14 years ago)
Author:
dpranke@chromium.org
Message:

2010-10-18 Dirk Pranke <dpranke@chromium.org>

Reviewed by Eric Seidel.

Re-submit a revised version of r69638 - enabling new-run-webkit-tests
under cygwin. The initial version had a bug in base:uri_to_test_name
that was causing tests to fail. This version corrects that bug, but
also makes the code safer by calling cygpath more reliably, and
leaving a long-running cygpath process open.

This patch also corrects a couple of minor bugs in http_lock_unittest,
chromium_unittest, and dedpulicate_tests_unittest that showed up
while testing this.

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

  • Scripts/webkitpy/common/system/path.py:
  • Scripts/webkitpy/common/system/path_unittest.py:
  • Scripts/webkitpy/layout_tests/deduplicate_tests_unittest.py:
  • Scripts/webkitpy/layout_tests/layout_package/dump_render_tree_thread.py:
  • Scripts/webkitpy/layout_tests/port/base.py:
  • Scripts/webkitpy/layout_tests/port/base_unittest.py:
  • Scripts/webkitpy/layout_tests/port/chromium.py:
  • Scripts/webkitpy/layout_tests/port/chromium_unittest.py:
  • Scripts/webkitpy/layout_tests/port/http_lock_unittest.py:
  • Scripts/webkitpy/layout_tests/run_webkit_tests.py:
Location:
trunk/WebKitTools
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r70006 r70012  
     12010-10-18  Dirk Pranke  <dpranke@chromium.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Re-submit a revised version of r69638 - enabling new-run-webkit-tests
     6        under cygwin. The initial version had a bug in base:uri_to_test_name
     7        that was causing tests to fail. This version corrects that bug, but
     8        also makes the code safer by calling cygpath more reliably, and
     9        leaving a long-running cygpath process open.
     10
     11        This patch also corrects a couple of minor bugs in http_lock_unittest,
     12        chromium_unittest, and dedpulicate_tests_unittest that showed up
     13        while testing this.
     14
     15        https://bugs.webkit.org/show_bug.cgi?id=47220
     16
     17        * Scripts/webkitpy/common/system/path.py:
     18        * Scripts/webkitpy/common/system/path_unittest.py:
     19        * Scripts/webkitpy/layout_tests/deduplicate_tests_unittest.py:
     20        * Scripts/webkitpy/layout_tests/layout_package/dump_render_tree_thread.py:
     21        * Scripts/webkitpy/layout_tests/port/base.py:
     22        * Scripts/webkitpy/layout_tests/port/base_unittest.py:
     23        * Scripts/webkitpy/layout_tests/port/chromium.py:
     24        * Scripts/webkitpy/layout_tests/port/chromium_unittest.py:
     25        * Scripts/webkitpy/layout_tests/port/http_lock_unittest.py:
     26        * Scripts/webkitpy/layout_tests/run_webkit_tests.py:
     27
    1282010-10-18  Eric Seidel  <eric@webkit.org>
    229
  • trunk/WebKitTools/Scripts/webkitpy/common/system/path.py

    r69674 r70012  
    2828
    2929"""generic routines to convert platform-specific paths to URIs."""
     30from __future__ import with_statement
     31
     32import atexit
     33import subprocess
    3034import sys
     35import threading
    3136import urllib
    3237
    3338
    34 def abspath_to_uri(path, executive, platform=None):
     39def abspath_to_uri(path, platform=None):
    3540    """Converts a platform-specific absolute path to a file: URL."""
    3641    if platform is None:
    3742        platform = sys.platform
    38     return "file:" + _escape(_convert_path(path, executive, platform))
     43    return "file:" + _escape(_convert_path(path, platform))
     44
     45
     46def cygpath(path):
     47    """Converts a cygwin path to Windows path."""
     48    return _CygPath.convert_using_singleton(path)
     49
     50
     51# Note that this object is not threadsafe and must only be called
     52# from multiple threads under protection of a lock (as is done in cygpath())
     53class _CygPath(object):
     54    """Manages a long-running 'cygpath' process for file conversion."""
     55    _lock = None
     56    _singleton = None
     57
     58    @staticmethod
     59    def stop_cygpath_subprocess():
     60        if not _CygPath._lock:
     61            return
     62
     63        with _CygPath._lock:
     64            if _CygPath._singleton:
     65                _CygPath._singleton.stop()
     66
     67    @staticmethod
     68    def convert_using_singleton(path):
     69        if not _CygPath._lock:
     70            _CygPath._lock = threading.Lock()
     71
     72        with _CygPath._lock:
     73            if not _CygPath._singleton:
     74                _CygPath._singleton = _CygPath()
     75                # Make sure the cygpath subprocess always gets shutdown cleanly.
     76                atexit.register(_CygPath.stop_cygpath_subprocess)
     77
     78            return _CygPath._singleton.convert(path)
     79
     80    def __init__(self):
     81        self._child_process = None
     82
     83    def start(self):
     84        assert(self._child_process is None)
     85        args = ['cygpath', '-f', '-', '-wa']
     86        self._child_process = subprocess.Popen(args,
     87                                               stdin=subprocess.PIPE,
     88                                               stdout=subprocess.PIPE)
     89
     90    def is_running(self):
     91        if not self._child_process:
     92            return False
     93        return self._child_process.returncode is None
     94
     95    def stop(self):
     96        if self._child_process:
     97            self._child_process.stdin.close()
     98            self._child_process.wait()
     99        self._child_process = None
     100
     101    def convert(self, path):
     102        if not self.is_running():
     103            self.start()
     104        self._child_process.stdin.write("%s\r\n" % path)
     105        self._child_process.stdin.flush()
     106        return self._child_process.stdout.readline().rstrip()
    39107
    40108
     
    48116
    49117
    50 def _convert_path(path, executive, platform):
     118def _convert_path(path, platform):
    51119    """Handles any os-specific path separators, mappings, etc."""
    52120    if platform == 'win32':
    53121        return _winpath_to_uri(path)
    54122    if platform == 'cygwin':
    55         return _winpath_to_uri(_cygpath(path, executive))
     123        return _winpath_to_uri(cygpath(path))
    56124    return _unixypath_to_uri(path)
    57125
     
    62130
    63131
    64 def _cygpath(path, executive):
    65     """Converts a cygwin path to Windows path."""
    66     return executive.run_command(['cygpath', '-wa', path],
    67                                  decode_output=False).rstrip()
    68 
    69 
    70132def _unixypath_to_uri(path):
    71133    """Converts a unix-style path to a file: URL."""
  • trunk/WebKitTools/Scripts/webkitpy/common/system/path_unittest.py

    r69363 r70012  
    2828
    2929import unittest
     30import sys
    3031
    3132import path
    3233
    33 
    3434class AbspathTest(unittest.TestCase):
    35     def run_command(self, args, **kwargs):
    36         self.assertEqual(args[0], 'cygpath')
    37         return self.cygpath_result
    38 
    3935    def assertMatch(self, test_path, expected_uri,
    40                     platform, cygpath_result=None):
    41         if platform == 'cygwin':
    42             self.cygpath_result = cygpath_result
    43         self.assertEqual(path.abspath_to_uri(test_path, executive=self,
    44                                              platform=platform),
     36                    platform=None):
     37        if platform == 'cygwin' and sys.platform != 'cygwin':
     38            return
     39        self.assertEqual(path.abspath_to_uri(test_path, platform=platform),
    4540                         expected_uri)
    4641
    4742    def test_abspath_to_uri_cygwin(self):
     43        if sys.platform != 'cygwin':
     44            return
     45
    4846        self.assertMatch('/cygdrive/c/foo/bar.html',
    49                          'file:///c:/foo/bar.html',
    50                          platform='cygwin',
    51                          cygpath_result='c:\\foo\\bar.html\n')
     47                         'file:///C:/foo/bar.html',
     48                         platform='cygwin')
    5249        self.assertEqual(path.abspath_to_uri('/cygdrive/c/foo/bar.html',
    53                                              executive=self,
    5450                                             platform='cygwin'),
    55                          'file:///c:/foo/bar.html')
     51                         'file:///C:/foo/bar.html')
    5652
    5753    def test_abspath_to_uri_darwin(self):
     
    6056                         platform='darwin')
    6157        self.assertEqual(path.abspath_to_uri("/foo/bar.html",
    62                                              executive=self,
    6358                                             platform='darwin'),
    6459                         "file:///foo/bar.html")
     
    6964                         platform='darwin')
    7065        self.assertEqual(path.abspath_to_uri("/foo/bar.html",
    71                                              executive=self,
    7266                                             platform='linux2'),
    7367                         "file:///foo/bar.html")
     
    7872                         platform='win32')
    7973        self.assertEqual(path.abspath_to_uri("c:\\foo\\bar.html",
    80                                              executive=self,
    8174                                             platform='win32'),
    8275                         "file:///c:/foo/bar.html")
     
    9285        # Note that you can't have '?' in a filename on windows.
    9386        self.assertMatch('/cygdrive/c/foo/bar + baz%.html',
    94                          'file:///c:/foo/bar%20+%20baz%25.html',
    95                          platform='cygwin',
    96                          cygpath_result='c:\\foo\\bar + baz%.html\n')
     87                         'file:///C:/foo/bar%20+%20baz%25.html',
     88                         platform='cygwin')
    9789
     90    def test_stop_cygpath_subprocess(self):
     91        if sys.platform != 'cygwin':
     92            return
     93
     94        # Call cygpath to ensure the subprocess is running.
     95        path.cygpath("/cygdrive/c/foo.txt")
     96        self.assertTrue(path._CygPath._singleton.is_running())
     97
     98        # Stop it.
     99        path._CygPath.stop_cygpath_subprocess()
     100
     101        # Ensure that it is stopped.
     102        self.assertFalse(path._CygPath._singleton.is_running())
    98103
    99104if __name__ == '__main__':
  • trunk/WebKitTools/Scripts/webkitpy/layout_tests/deduplicate_tests_unittest.py

    r67588 r70012  
    206206            self.assertEquals(expected,
    207207                              deduplicate_tests.get_relative_test_path(*inputs))
     208
     209if __name__ == '__main__':
     210    unittest.main()
  • trunk/WebKitTools/Scripts/webkitpy/layout_tests/port/base.py

    r69820 r70012  
    5050from webkitpy.common.system import logutils
    5151from webkitpy.common.system.executive import Executive, ScriptError
     52from webkitpy.common.system.path import abspath_to_uri
    5253from webkitpy.common.system.user import User
    5354
     
    337338            return "%s://127.0.0.1:%u/%s" % (protocol, port, relative_path)
    338339
    339         abspath = os.path.abspath(filename)
    340 
    341         # On Windows, absolute paths are of the form "c:\foo.txt". However,
    342         # all current browsers (except for Opera) normalize file URLs by
    343         # prepending an additional "/" as if the absolute path was
    344         # "/c:/foo.txt". This means that all file URLs end up with "file:///"
    345         # at the beginning.
    346         if sys.platform == 'win32':
    347             abspath = '/' + abspath.replace('\\', '/')
    348 
    349         return "file://" + abspath
     340        return abspath_to_uri(os.path.abspath(filename))
    350341
    351342    def tests(self, paths):
     
    396387        test = uri
    397388        if uri.startswith("file:///"):
    398             if sys.platform == 'win32':
    399                 test = test.replace('file:///', '')
    400                 test = test.replace('/', '\\')
    401             else:
    402                 test = test.replace('file://', '')
    403             return self.relative_test_filename(test)
     389            prefix = abspath_to_uri(self.layout_tests_dir()) + "/"
     390            return test[len(prefix):]
    404391
    405392        if uri.startswith("http://127.0.0.1:8880/"):
  • trunk/WebKitTools/Scripts/webkitpy/layout_tests/port/base_unittest.py

    r69820 r70012  
    3434import unittest
    3535
     36from webkitpy.common.system.path import abspath_to_uri
    3637from webkitpy.common.system.executive import Executive, ScriptError
    3738from webkitpy.thirdparty.mock import Mock
     
    245246
    246247        self.assertEqual(port.filename_to_uri(test_file),
    247                          prefix + path)
    248 
     248                         abspath_to_uri(test_file))
    249249
    250250
  • trunk/WebKitTools/Scripts/webkitpy/layout_tests/port/chromium.py

    r69820 r70012  
    4444import webbrowser
    4545
     46from webkitpy.common.system.executive import Executive
     47from webkitpy.common.system.path import cygpath
     48from webkitpy.layout_tests.layout_package import test_expectations
     49
    4650import base
    4751import http_server
     
    345349        return self.path_from_webkit_base('LayoutTests', 'platform', platform)
    346350
     351    def _convert_path(self, path):
     352        """Handles filename conversion for subprocess command line args."""
     353        # See note above in diff_image() for why we need this.
     354        if sys.platform == 'cygwin':
     355            return cygpath(path)
     356        return path
     357
    347358    def _path_to_image_diff(self):
    348359        binary_name = 'image_diff'
     
    364375        driver_args = []
    365376        if self._image_path:
    366             driver_args.append("--pixel-tests=" + self._image_path)
     377            # See note above in diff_image() for why we need _convert_path().
     378            driver_args.append("--pixel-tests=" +
     379                               self._port._convert_path(self._image_path))
    367380
    368381        if self._options.use_drt:
  • trunk/WebKitTools/Scripts/webkitpy/layout_tests/port/chromium_unittest.py

    r69169 r70012  
    177177                            return_stderr=True,
    178178                            decode_output=False):
    179                 return self._result
     179                if return_exit_code:
     180                    return self._result
     181                return ''
    180182
    181183        options = EmptyOptions()
  • trunk/WebKitTools/Scripts/webkitpy/layout_tests/port/http_lock_unittest.py

    r69578 r70012  
    4444    def clean_all_lockfile(self):
    4545        if os.path.exists(self.guard_lock_file):
    46             os.unlink(guard_lock_file)
     46            os.unlink(self.guard_lock_file)
    4747        lock_list = glob.glob(self.lock_file_path_prefix + '*')
    4848        for file_name in lock_list:
Note: See TracChangeset for help on using the changeset viewer.