Tools/Scripts: eliminate find_test_files from Port class.
authorloislo@chromium.org <loislo@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Dec 2011 08:44:20 +0000 (08:44 +0000)
committerloislo@chromium.org <loislo@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Dec 2011 08:44:20 +0000 (08:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=73553

rebaseline.py and chromium_gpu.py use Port.find_test_files() the same way as it is used in Port.tests()
I'd like to replace all calls to find_test_files with tests and eliminate find_tests_files.
Also I'll move _is_test_file() and related functions close to Port.tests().

Reviewed by Dirk Pranke.

* Scripts/webkitpy/layout_tests/port/base.py:
(Port.tests):
(Port.is_reference_html_file):
(Port._has_supported_extension):
(Port._is_test_file):
* Scripts/webkitpy/layout_tests/port/base_unittest.py:
(PortTest.test_find_no_paths_specified):
(PortTest.test_find_one_test):
(PortTest.test_find_glob):
(PortTest.test_find_with_skipped_directories):
(PortTest.test_find_with_skipped_directories_2):
(PortTest.test_is_test_file):
* Scripts/webkitpy/layout_tests/port/chromium_gpu.py:
(_default_tests_paths):
(ChromiumGpuLinuxPort.tests):
(ChromiumGpuCgMacPort.tests):
(ChromiumGpuMacPort.tests):
* Scripts/webkitpy/layout_tests/port/chromium_gpu_unittest.py:
(ChromiumGpuTest.test_default_tests_paths.test_paths):
(ChromiumGpuTest.test_default_tests_paths):
(ChromiumGpuTest.test_test_files.test_paths):
(ChromiumGpuTest):
(ChromiumGpuTest.test_test_files):
* Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py:
(get_tests_run.RecordingTestDriver.run_test):
* Scripts/webkitpy/tool/commands/rebaseline.py:
(OptimizeBaselines._optimize_baseline):
(OptimizeBaselines.execute):
(AnalyzeBaselines._analyze_baseline):
(AnalyzeBaselines.execute):

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

Tools/ChangeLog
Tools/Scripts/webkitpy/layout_tests/port/base.py
Tools/Scripts/webkitpy/layout_tests/port/base_unittest.py
Tools/Scripts/webkitpy/layout_tests/port/chromium_gpu.py
Tools/Scripts/webkitpy/layout_tests/port/chromium_gpu_unittest.py
Tools/Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py
Tools/Scripts/webkitpy/tool/commands/rebaseline.py

index a6f2591c70d831c8e6a33d28c604d82011b7708a..219b80e0932b5d47efb4e99971c09ab5ab2a74af 100644 (file)
@@ -1,3 +1,45 @@
+2011-12-01  Ilya Tikhonovsky  <loislo@chromium.org>
+
+        Tools/Scripts: eliminate find_test_files from Port class.
+        https://bugs.webkit.org/show_bug.cgi?id=73553
+
+        rebaseline.py and chromium_gpu.py use Port.find_test_files() the same way as it is used in Port.tests()
+        I'd like to replace all calls to find_test_files with tests and eliminate find_tests_files.
+        Also I'll move _is_test_file() and related functions close to Port.tests().
+
+        Reviewed by Dirk Pranke.
+
+        * Scripts/webkitpy/layout_tests/port/base.py:
+        (Port.tests):
+        (Port.is_reference_html_file):
+        (Port._has_supported_extension):
+        (Port._is_test_file):
+        * Scripts/webkitpy/layout_tests/port/base_unittest.py:
+        (PortTest.test_find_no_paths_specified):
+        (PortTest.test_find_one_test):
+        (PortTest.test_find_glob):
+        (PortTest.test_find_with_skipped_directories):
+        (PortTest.test_find_with_skipped_directories_2):
+        (PortTest.test_is_test_file):
+        * Scripts/webkitpy/layout_tests/port/chromium_gpu.py:
+        (_default_tests_paths):
+        (ChromiumGpuLinuxPort.tests):
+        (ChromiumGpuCgMacPort.tests):
+        (ChromiumGpuMacPort.tests):
+        * Scripts/webkitpy/layout_tests/port/chromium_gpu_unittest.py:
+        (ChromiumGpuTest.test_default_tests_paths.test_paths):
+        (ChromiumGpuTest.test_default_tests_paths):
+        (ChromiumGpuTest.test_test_files.test_paths):
+        (ChromiumGpuTest):
+        (ChromiumGpuTest.test_test_files):
+        * Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py:
+        (get_tests_run.RecordingTestDriver.run_test):
+        * Scripts/webkitpy/tool/commands/rebaseline.py:
+        (OptimizeBaselines._optimize_baseline):
+        (OptimizeBaselines.execute):
+        (AnalyzeBaselines._analyze_baseline):
+        (AnalyzeBaselines.execute):
+
 2011-12-01  Hajime Morrita  <morrita@chromium.org>
 
         JS_INLINE and WTF_INLINE should be visible from WebCore
index f46632f5f9abee7b311f45a8783ae6addf52cc6b..0498bd7e632134f04f8f48736b2e08cde3868752 100755 (executable)
@@ -429,9 +429,26 @@ class Port(object):
     def _get_reftest_list(self, test_name):
         dirname = self._filesystem.join(self.layout_tests_dir(), self._filesystem.dirname(test_name))
         if dirname not in self._reftest_list:
-            self._reftest_list[dirname] = _parse_reftest_list(self._filesystem, dirname)
+            self._reftest_list[dirname] = Port._parse_reftest_list(self._filesystem, dirname)
         return self._reftest_list[dirname]
 
+    @staticmethod
+    def _parse_reftest_list(filesystem, test_dirpath):
+        reftest_list_path = filesystem.join(test_dirpath, 'reftest.list')
+        if not filesystem.isfile(reftest_list_path):
+            return None
+        reftest_list_file = filesystem.read_text_file(reftest_list_path)
+
+        parsed_list = dict()
+        for line in reftest_list_file.split('\n'):
+            line = re.sub('#.+$', '', line)
+            split_line = line.split()
+            if len(split_line) < 3:
+                continue
+            expectation_type, test_file, ref_file = split_line
+            parsed_list[filesystem.join(test_dirpath, test_file)] = (expectation_type, filesystem.join(test_dirpath, ref_file))
+        return parsed_list
+
     def _reference_file_for(self, test_name, expectation):
         reftest_list = self._get_reftest_list(test_name)
         if not reftest_list:
@@ -490,13 +507,34 @@ class Port(object):
 
     def tests(self, paths):
         """Return the list of tests found."""
-        # FIXME: Should port.find_test_files() return normalized, relative test names?
-        return set([self.relative_test_filename(f) for f in self.find_test_files(paths)])
-
-    def find_test_files(self, paths):
         # When collecting test cases, skip these directories
         skipped_directories = set(['.svn', '_svn', 'resources', 'script-tests', 'reference', 'reftest'])
-        return find_files.find(self.filesystem, self.layout_tests_dir(), paths, skipped_directories, _is_test_file)
+        files = find_files.find(self.filesystem, self.layout_tests_dir(), paths, skipped_directories, Port._is_test_file)
+        return set([self.relative_test_filename(f) for f in files])
+
+    # When collecting test cases, we include any file with these extensions.
+    _supported_file_extensions = set(['.html', '.shtml', '.xml', '.xhtml', '.pl',
+                                      '.htm', '.php', '.svg', '.mht'])
+
+    @staticmethod
+    def is_reference_html_file(filesystem, dirname, filename):
+        if filename.startswith('ref-') or filename.endswith('notref-'):
+            return True
+        filename_wihout_ext, unused = filesystem.splitext(filename)
+        for suffix in ['-expected', '-expected-mismatch', '-ref', '-notref']:
+            if filename_wihout_ext.endswith(suffix):
+                return True
+        return False
+
+    @staticmethod
+    def _has_supported_extension(filesystem, filename):
+        """Return true if filename is one of the file extensions we want to run a test on."""
+        extension = filesystem.splitext(filename)[1]
+        return extension in Port._supported_file_extensions
+
+    @staticmethod
+    def _is_test_file(filesystem, dirname, filename):
+        return Port._has_supported_extension(filesystem, filename) and not Port.is_reference_html_file(filesystem, dirname, filename)
 
     def test_dirs(self):
         """Returns the list of top-level test directories."""
@@ -1028,44 +1066,3 @@ class Port(object):
     def _driver_class(self):
         """Returns the port's driver implementation."""
         raise NotImplementedError('Port._driver_class')
-
-
-# When collecting test cases, we include any file with these extensions.
-_supported_file_extensions = set(['.html', '.shtml', '.xml', '.xhtml', '.pl', '.htm', '.php', '.svg', '.mht'])
-
-
-def is_reference_html_file(filesystem, dirname, filename):
-    if filename.startswith('ref-') or filename.endswith('notref-'):
-        return True
-    filename_wihout_ext, unused = filesystem.splitext(filename)
-    for suffix in ['-expected', '-expected-mismatch', '-ref', '-notref']:
-        if filename_wihout_ext.endswith(suffix):
-            return True
-    return False
-
-
-def _has_supported_extension(filesystem, filename):
-    """Return true if filename is one of the file extensions we want to run a test on."""
-    extension = filesystem.splitext(filename)[1]
-    return extension in _supported_file_extensions
-
-
-def _is_test_file(filesystem, dirname, filename):
-    return _has_supported_extension(filesystem, filename) and not is_reference_html_file(filesystem, dirname, filename)
-
-
-def _parse_reftest_list(filesystem, test_dirpath):
-    reftest_list_path = filesystem.join(test_dirpath, 'reftest.list')
-    if not filesystem.isfile(reftest_list_path):
-        return None
-    reftest_list_file = filesystem.read_text_file(reftest_list_path)
-
-    parsed_list = dict()
-    for line in reftest_list_file.split('\n'):
-        line = re.sub('#.+$', '', line)
-        split_line = line.split()
-        if len(split_line) < 3:
-            continue
-        expectation_type, test_file, ref_file = split_line
-        parsed_list[filesystem.join(test_dirpath, test_file)] = (expectation_type, filesystem.join(test_dirpath, ref_file))
-    return parsed_list
index 359053308126e8d9288c4d83cc196dc7653d89c1..706c94d15ea8544a0c004289c61dc05a80cb7823 100644 (file)
@@ -42,8 +42,6 @@ from webkitpy.common.system.executive_mock import MockExecutive
 from webkitpy.common.host_mock import MockHost
 
 from webkitpy.layout_tests.port import Port, Driver, DriverOutput
-from webkitpy.layout_tests.port.base import _is_test_file
-from webkitpy.layout_tests.port.base import _parse_reftest_list
 from webkitpy.layout_tests.port.test import TestPort
 
 import config
@@ -280,43 +278,43 @@ class PortTest(unittest.TestCase):
     def test_find_no_paths_specified(self):
         port = TestPort()
         layout_tests_dir = port.layout_tests_dir()
-        tests = port.find_test_files([])
+        tests = port.tests([])
         self.assertNotEqual(len(tests), 0)
 
     def test_find_one_test(self):
         port = TestPort()
-        tests = port.find_test_files(['failures/expected/image.html'])
+        tests = port.tests(['failures/expected/image.html'])
         self.assertEqual(len(tests), 1)
 
     def test_find_glob(self):
         port = TestPort()
-        tests = port.find_test_files(['failures/expected/im*'])
+        tests = port.tests(['failures/expected/im*'])
         self.assertEqual(len(tests), 2)
 
     def test_find_with_skipped_directories(self):
         port = TestPort()
-        tests = port.find_test_files('userscripts')
+        tests = port.tests('userscripts')
         self.assertTrue('userscripts/resources/iframe.html' not in tests)
 
     def test_find_with_skipped_directories_2(self):
         port = TestPort()
-        tests = port.find_test_files(['userscripts/resources'])
+        tests = port.tests(['userscripts/resources'])
         self.assertEqual(tests, set([]))
 
     def test_is_test_file(self):
         filesystem = MockFileSystem()
-        self.assertTrue(_is_test_file(filesystem, '', 'foo.html'))
-        self.assertTrue(_is_test_file(filesystem, '', 'foo.shtml'))
-        self.assertTrue(_is_test_file(filesystem, '', 'test-ref-test.html'))
-        self.assertFalse(_is_test_file(filesystem, '', 'foo.png'))
-        self.assertFalse(_is_test_file(filesystem, '', 'foo-expected.html'))
-        self.assertFalse(_is_test_file(filesystem, '', 'foo-expected-mismatch.html'))
-        self.assertFalse(_is_test_file(filesystem, '', 'foo-ref.html'))
-        self.assertFalse(_is_test_file(filesystem, '', 'foo-notref.html'))
-        self.assertFalse(_is_test_file(filesystem, '', 'foo-notref.xht'))
-        self.assertFalse(_is_test_file(filesystem, '', 'foo-ref.xhtml'))
-        self.assertFalse(_is_test_file(filesystem, '', 'ref-foo.html'))
-        self.assertFalse(_is_test_file(filesystem, '', 'notref-foo.xhr'))
+        self.assertTrue(Port._is_test_file(filesystem, '', 'foo.html'))
+        self.assertTrue(Port._is_test_file(filesystem, '', 'foo.shtml'))
+        self.assertTrue(Port._is_test_file(filesystem, '', 'test-ref-test.html'))
+        self.assertFalse(Port._is_test_file(filesystem, '', 'foo.png'))
+        self.assertFalse(Port._is_test_file(filesystem, '', 'foo-expected.html'))
+        self.assertFalse(Port._is_test_file(filesystem, '', 'foo-expected-mismatch.html'))
+        self.assertFalse(Port._is_test_file(filesystem, '', 'foo-ref.html'))
+        self.assertFalse(Port._is_test_file(filesystem, '', 'foo-notref.html'))
+        self.assertFalse(Port._is_test_file(filesystem, '', 'foo-notref.xht'))
+        self.assertFalse(Port._is_test_file(filesystem, '', 'foo-ref.xhtml'))
+        self.assertFalse(Port._is_test_file(filesystem, '', 'ref-foo.html'))
+        self.assertFalse(Port._is_test_file(filesystem, '', 'notref-foo.xhr'))
 
     def test_parse_reftest_list(self):
         port = TestPort()
@@ -326,11 +324,12 @@ class PortTest(unittest.TestCase):
         "!= test-2.html test-notref.html # more comments",
         "== test-3.html test-ref.html"])
 
-        reftest_list = _parse_reftest_list(port.host.filesystem, 'bar')
+        reftest_list = Port._parse_reftest_list(port.host.filesystem, 'bar')
         self.assertEqual(reftest_list, {'bar/test.html': ('==', 'bar/test-ref.html'),
             'bar/test-2.html': ('!=', 'bar/test-notref.html'),
             'bar/test-3.html': ('==', 'bar/test-ref.html')})
 
+
 class VirtualTest(unittest.TestCase):
     """Tests that various methods expected to be virtual are."""
     def assertVirtual(self, method, *args, **kwargs):
index 266103341e4d374477e36c08a1f012d2813722e9..1169d76421312fdcda1e80200edc7a1066fff16d 100644 (file)
@@ -74,31 +74,30 @@ def _set_gpu_options(port, graphics_type='gpu'):
         port._options.builder_name += ' - GPU'
 
 
-def _tests(port, paths):
+def _default_tests_paths(port):
+    paths = []
+    if (port.name() != 'chromium-gpu-mac-leopard' and
+        port.name() != 'chromium-gpu-cg-mac-leopard'):
+        # Only run tests requiring accelerated compositing on platforms that
+        # support it.
+        # FIXME: we should add the above paths here as well but let's test
+        # the waters with media first.
+        paths += ['media']
+
+    if not port.name().startswith('chromium-gpu-cg-mac'):
+        # Canvas is not yet accelerated on the Mac, so there's no point
+        # in running the tests there.
+        paths += ['fast/canvas', 'canvas/philip']
+
     if not paths:
-        paths = []
-        if (port.name() != 'chromium-gpu-mac-leopard' and
-            port.name() != 'chromium-gpu-cg-mac-leopard'):
-            # Only run tests requiring accelerated compositing on platforms that
-            # support it.
-            # FIXME: we should add the above paths here as well but let's test
-            # the waters with media first.
-            paths += ['media']
-
-        if not port.name().startswith('chromium-gpu-cg-mac'):
-            # Canvas is not yet accelerated on the Mac, so there's no point
-            # in running the tests there.
-            paths += ['fast/canvas', 'canvas/philip']
-
-        if not paths:
-            # FIXME: This is a hack until we can turn of the webkit_gpu
-            # tests on the bots. If paths is empty, port.find_test_files()
-            # finds *everything*. However, we have to return something,
-            # or NRWT thinks there's something wrong. So, we return a single
-            # short directory. See https://bugs.webkit.org/show_bug.cgi?id=72498.
-            paths = ['fast/html']
-
-    return set([port.relative_test_filename(f) for f in port.find_test_files(paths)])
+        # FIXME: This is a hack until we can turn of the webkit_gpu
+        # tests on the bots. If paths is empty, port.tests()
+        # finds *everything*. However, we have to return something,
+        # or NRWT thinks there's something wrong. So, we return a single
+        # short directory. See https://bugs.webkit.org/show_bug.cgi?id=72498.
+        paths = ['fast/html']
+
+    return paths
 
 
 class ChromiumGpuLinuxPort(chromium_linux.ChromiumLinuxPort):
@@ -112,7 +111,8 @@ class ChromiumGpuLinuxPort(chromium_linux.ChromiumLinuxPort):
                 chromium_linux.ChromiumLinuxPort.baseline_search_path(self))
 
     def tests(self, paths):
-        return _tests(self, paths)
+        paths = paths or _default_tests_paths(self)
+        return chromium_linux.ChromiumLinuxPort.tests(self, paths)
 
 
 class ChromiumGpuCgMacPort(chromium_mac.ChromiumMacPort):
@@ -125,7 +125,8 @@ class ChromiumGpuCgMacPort(chromium_mac.ChromiumMacPort):
                 chromium_mac.ChromiumMacPort.baseline_search_path(self))
 
     def tests(self, paths):
-        return _tests(self, paths)
+        paths = paths or _default_tests_paths(self)
+        return chromium_mac.ChromiumMacPort.tests(self, paths)
 
 
 class ChromiumGpuMacPort(chromium_mac.ChromiumMacPort):
@@ -138,7 +139,8 @@ class ChromiumGpuMacPort(chromium_mac.ChromiumMacPort):
                 chromium_mac.ChromiumMacPort.baseline_search_path(self))
 
     def tests(self, paths):
-        return _tests(self, paths)
+        paths = paths or _default_tests_paths(self)
+        return chromium_mac.ChromiumMacPort.tests(self, paths)
 
 
 class ChromiumGpuWinPort(chromium_win.ChromiumWinPort):
@@ -151,4 +153,5 @@ class ChromiumGpuWinPort(chromium_win.ChromiumWinPort):
                 chromium_win.ChromiumWinPort.baseline_search_path(self))
 
     def tests(self, paths):
-        return _tests(self, paths)
+        paths = paths or _default_tests_paths(self)
+        return chromium_win.ChromiumWinPort.tests(self, paths)
index 0795982244fa1ca285d97f2e2f53624d4449f748..f674c436d214786ae7687e9ee027c1a58c36214e 100755 (executable)
@@ -32,6 +32,7 @@ import chromium_gpu
 from webkitpy.tool.mocktool import MockOptions
 from webkitpy.common.host_mock import MockHost
 from webkitpy.layout_tests.port import port_testcase
+from webkitpy.common.system.filesystem_mock import MockFileSystem
 
 
 class ChromiumGpuTest(unittest.TestCase):
@@ -115,6 +116,34 @@ class ChromiumGpuTest(unittest.TestCase):
         port = host.port_factory.get('chromium-gpu-mac')
         self.assertEquals('gpu', port.graphics_type())
 
+    def test_default_tests_paths(self):
+        host = MockHost()
+
+        def test_paths(port_name):
+            return chromium_gpu._default_tests_paths(host.port_factory.get(port_name))
+
+        self.assertEqual(test_paths('chromium-gpu-linux'), ['media', 'fast/canvas', 'canvas/philip'])
+        self.assertEqual(test_paths('chromium-gpu-mac-leopard'), ['fast/canvas', 'canvas/philip'])
+        self.assertEqual(test_paths('chromium-gpu-cg-mac-leopard'), ['fast/html'])
+
+    def test_test_files(self):
+        host = MockHost()
+        files = {
+            '/mock-checkout/LayoutTests/canvas/philip/test.html': '',
+            '/mock-checkout/LayoutTests/fast/canvas/test.html': '',
+            '/mock-checkout/LayoutTests/fast/html/test.html': '',
+            '/mock-checkout/LayoutTests/media/test.html': '',
+            '/mock-checkout/LayoutTests/foo/bar.html': '',
+        }
+        host.filesystem = MockFileSystem(files)
+
+        def test_paths(port_name):
+            return host.port_factory.get(port_name).tests([])
+
+        self.assertEqual(test_paths('chromium-gpu-linux'), set(['canvas/philip/test.html', 'fast/canvas/test.html', 'media/test.html']))
+        self.assertEqual(test_paths('chromium-gpu-mac-leopard'), set(['canvas/philip/test.html', 'fast/canvas/test.html']))
+        self.assertEqual(test_paths('chromium-gpu-cg-mac-leopard'), set(['fast/html/test.html']))
+
 
 if __name__ == '__main__':
     port_testcase.main()
index 50b59aeef03fe93aa605cf054414904e51ad4f92..ff39a564ef8d61cf0fbdcdf0583ea4daee4d16f5 100755 (executable)
@@ -65,8 +65,8 @@ from webkitpy.common.host_mock import MockHost
 
 from webkitpy.layout_tests import port
 from webkitpy.layout_tests import run_webkit_tests
+from webkitpy.layout_tests.port import Port
 from webkitpy.layout_tests.port.test import TestPort, TestDriver, unit_test_filesystem
-from webkitpy.layout_tests.port.base import is_reference_html_file
 from webkitpy.python24.versioning import compare_version
 from webkitpy.test.skip import skip_if
 
@@ -168,7 +168,7 @@ def get_tests_run(extra_args=None, tests_included=False, flatten_batches=False,
             # is explicitly given.
             filesystem = self._port.host.filesystem
             dirname, filename = filesystem.split(test_name)
-            if include_reference_html or not is_reference_html_file(filesystem, dirname, filename):
+            if include_reference_html or not Port.is_reference_html_file(filesystem, dirname, filename):
                 self._current_test_batch.append(test_name)
             return TestDriver.run_test(self, test_input)
 
index 5db33335fba73fa854449538cce0caffd7c703ec..515ff7dfa581d17b49699531b70d5e1ab4f146e4 100644 (file)
@@ -111,14 +111,11 @@ class OptimizeBaselines(AbstractDeclarativeCommand):
             if not self._baseline_optimizer.optimize(baseline_name):
                 print "Hueristics failed to optimize %s" % baseline_name
 
-    def _to_test_name(self, file_name): 
-        return self._tool.filesystem.relpath(file_name, self._port.layout_tests_dir())
-
     def execute(self, options, args, tool):
         self._baseline_optimizer = BaselineOptimizer(tool)
         self._port = tool.port_factory.get("chromium-win-win7")  # FIXME: This should be selectable.
 
-        for test_name in map(self._to_test_name, self._port.find_test_files(args)):
+        for test_name in self._port.tests(args):
             print "Optimizing %s." % test_name
             self._optimize_baseline(test_name)
 
@@ -141,14 +138,11 @@ class AnalyzeBaselines(AbstractDeclarativeCommand):
             directories_by_result = self._baseline_optimizer.directories_by_result(baseline_name)
             self._print(baseline_name, directories_by_result)
 
-    def _to_test_name(self, file_name): 
-        return self._tool.filesystem.relpath(file_name, self._port.layout_tests_dir())
-
     def execute(self, options, args, tool):
         self._baseline_optimizer = BaselineOptimizer(tool)
         self._port = tool.port_factory.get("chromium-win-win7")  # FIXME: This should be selectable.
 
-        for test_name in map(self._to_test_name, self._port.find_test_files(args)):
+        for test_name in self._port.tests(args):
             self._analyze_baseline(test_name)