Title: [283037] trunk/Tools
Revision
283037
Author
[email protected]
Date
2021-09-24 05:58:41 -0700 (Fri, 24 Sep 2021)

Log Message

LayoutTestFinder should return tests in order
https://bugs.webkit.org/show_bug.cgi?id=230684

Reviewed by Jonathan Bedard.

It has always been intended that LayoutTestFinder return tests in a deterministic order;
however, a bug in find_files means that directories found by glob aren't sorted, and hence
running run-webkit-tests with no arguments ends up running the top-level directories in a
non-deterministic order.

* Scripts/webkitpy/common/find_files.py:
(_normalized_find):
(_normalized_find.sort_by_directory_key):
* Scripts/webkitpy/common/find_files_unittest.py:
(TestWinNormalize.assert_filesystem_normalizes):
(TestWinNormalize.test_win):
(TestFindFiles):
(TestFindFiles.test_directory_sort_key):
(TestFindFiles.test_directory_sort_key_with_paths):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (283036 => 283037)


--- trunk/Tools/ChangeLog	2021-09-24 12:41:04 UTC (rev 283036)
+++ trunk/Tools/ChangeLog	2021-09-24 12:58:41 UTC (rev 283037)
@@ -1,3 +1,25 @@
+2021-09-24  Sam Sneddon  <[email protected]>
+
+        LayoutTestFinder should return tests in order
+        https://bugs.webkit.org/show_bug.cgi?id=230684
+
+        Reviewed by Jonathan Bedard.
+
+        It has always been intended that LayoutTestFinder return tests in a deterministic order;
+        however, a bug in find_files means that directories found by glob aren't sorted, and hence
+        running run-webkit-tests with no arguments ends up running the top-level directories in a
+        non-deterministic order.
+
+        * Scripts/webkitpy/common/find_files.py:
+        (_normalized_find):
+        (_normalized_find.sort_by_directory_key):
+        * Scripts/webkitpy/common/find_files_unittest.py:
+        (TestWinNormalize.assert_filesystem_normalizes):
+        (TestWinNormalize.test_win):
+        (TestFindFiles):
+        (TestFindFiles.test_directory_sort_key):
+        (TestFindFiles.test_directory_sort_key_with_paths):
+
 2021-09-24  Youenn Fablet  <[email protected]>
 
         <video> element rendered incorrectly when provided with a portrait orientation stream in Safari 15

Modified: trunk/Tools/Scripts/webkitpy/common/find_files.py (283036 => 283037)


--- trunk/Tools/Scripts/webkitpy/common/find_files.py	2021-09-24 12:41:04 UTC (rev 283036)
+++ trunk/Tools/Scripts/webkitpy/common/find_files.py	2021-09-24 12:58:41 UTC (rev 283037)
@@ -73,12 +73,13 @@
           Glob patterns are ok.
     """
 
-    paths_to_walk = itertools.chain(*(filesystem.glob(path) for path in paths))
-
     def sort_by_directory_key(files_list):
-        if directory_sort_key:
-            files_list.sort(key=directory_sort_key)
-        return files_list
+        if not directory_sort_key:
+            return files_list[:]
 
+        return sorted(files_list, key=directory_sort_key)
+
+    paths_to_walk = itertools.chain(*(sort_by_directory_key(filesystem.glob(path)) for path in paths))
+
     all_files = itertools.chain(*(sort_by_directory_key(filesystem.files_under(path, skipped_directories, file_filter)) for path in paths_to_walk))
     return all_files

Modified: trunk/Tools/Scripts/webkitpy/common/find_files_unittest.py (283036 => 283037)


--- trunk/Tools/Scripts/webkitpy/common/find_files_unittest.py	2021-09-24 12:41:04 UTC (rev 283036)
+++ trunk/Tools/Scripts/webkitpy/common/find_files_unittest.py	2021-09-24 12:58:41 UTC (rev 283037)
@@ -26,6 +26,8 @@
 # (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 itertools
+import random
 import sys
 import unittest
 
@@ -32,6 +34,7 @@
 import webkitpy.common.find_files as find_files
 
 from webkitpy.common.system.filesystem import FileSystem
+from webkitpy.common.system.filesystem_mock import MockFileSystem
 
 
 class MockWinFileSystem(object):
@@ -44,9 +47,18 @@
 
 class TestWinNormalize(unittest.TestCase):
     def assert_filesystem_normalizes(self, filesystem):
-        self.assertEqual(find_files._normalize(filesystem, "c:\\foo",
-            ['fast/html', 'fast/canvas/*', 'compositing/foo.html']),
-            ['c:\\foo\\fast\\html', 'c:\\foo\\fast\\canvas\\*', 'c:\\foo\\compositing\\foo.html'])
+        self.assertEqual(
+            find_files._normalize(
+                filesystem,
+                "c:\\foo",
+                ['fast/html', 'fast/canvas/*', 'compositing/foo.html'],
+            ),
+            [
+                'c:\\foo\\fast\\html',
+                'c:\\foo\\fast\\canvas\\*',
+                'c:\\foo\\compositing\\foo.html',
+            ],
+        )
 
     def test_mocked_win(self):
         # This tests test_files.normalize, using portable behavior emulating
@@ -60,3 +72,34 @@
         if not sys.platform.startswith('win'):
             return
         self.assert_filesystem_normalizes(FileSystem())
+
+
+class TestFindFiles(unittest.TestCase):
+    def test_directory_sort_key(self):
+        filenames = [chr(o) for o in range(ord("a"), ord("z") + 1)]
+        fs = MockFileSystem(
+            files={c: "" for c in random.sample(filenames, len(filenames))}
+        )
+        self.assertEqual(
+            list(find_files.find(fs, "", directory_sort_key=lambda x: x)),
+            sorted(filenames),
+        )
+
+    def test_directory_sort_key_with_paths(self):
+        filenames = ["/".join(i) for i in itertools.product("abcde", "12345")]
+        fs = MockFileSystem(
+            files={c: "" for c in random.sample(filenames, len(filenames))}
+        )
+
+        test_subset = random.sample("abcde", 3)
+        self.assertEqual(
+            list(
+                find_files.find(
+                    fs,
+                    "",
+                    paths=[i + "/*" for i in test_subset],
+                    directory_sort_key=lambda x: x,
+                )
+            ),
+            ["/".join(i) for i in itertools.product(test_subset, "12345")],
+        )
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to