Changeset 283037 in webkit


Ignore:
Timestamp:
Sep 24, 2021, 5:58:41 AM (4 years ago)
Author:
Sam Sneddon
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):

Location:
trunk/Tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r283035 r283037  
     12021-09-24  Sam Sneddon  <gsnedders@apple.com>
     2
     3        LayoutTestFinder should return tests in order
     4        https://bugs.webkit.org/show_bug.cgi?id=230684
     5
     6        Reviewed by Jonathan Bedard.
     7
     8        It has always been intended that LayoutTestFinder return tests in a deterministic order;
     9        however, a bug in find_files means that directories found by glob aren't sorted, and hence
     10        running run-webkit-tests with no arguments ends up running the top-level directories in a
     11        non-deterministic order.
     12
     13        * Scripts/webkitpy/common/find_files.py:
     14        (_normalized_find):
     15        (_normalized_find.sort_by_directory_key):
     16        * Scripts/webkitpy/common/find_files_unittest.py:
     17        (TestWinNormalize.assert_filesystem_normalizes):
     18        (TestWinNormalize.test_win):
     19        (TestFindFiles):
     20        (TestFindFiles.test_directory_sort_key):
     21        (TestFindFiles.test_directory_sort_key_with_paths):
     22
    1232021-09-24  Youenn Fablet  <youenn@apple.com>
    224
  • trunk/Tools/Scripts/webkitpy/common/find_files.py

    r136545 r283037  
    7474    """
    7575
    76     paths_to_walk = itertools.chain(*(filesystem.glob(path) for path in paths))
     76    def sort_by_directory_key(files_list):
     77        if not directory_sort_key:
     78            return files_list[:]
    7779
    78     def sort_by_directory_key(files_list):
    79         if directory_sort_key:
    80             files_list.sort(key=directory_sort_key)
    81         return files_list
     80        return sorted(files_list, key=directory_sort_key)
     81
     82    paths_to_walk = itertools.chain(*(sort_by_directory_key(filesystem.glob(path)) for path in paths))
    8283
    8384    all_files = itertools.chain(*(sort_by_directory_key(filesystem.files_under(path, skipped_directories, file_filter)) for path in paths_to_walk))
  • trunk/Tools/Scripts/webkitpy/common/find_files_unittest.py

    r277853 r283037  
    2727# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2828
     29import itertools
     30import random
    2931import sys
    3032import unittest
     
    3335
    3436from webkitpy.common.system.filesystem import FileSystem
     37from webkitpy.common.system.filesystem_mock import MockFileSystem
    3538
    3639
     
    4548class TestWinNormalize(unittest.TestCase):
    4649    def assert_filesystem_normalizes(self, filesystem):
    47         self.assertEqual(find_files._normalize(filesystem, "c:\\foo",
    48             ['fast/html', 'fast/canvas/*', 'compositing/foo.html']),
    49             ['c:\\foo\\fast\\html', 'c:\\foo\\fast\\canvas\\*', 'c:\\foo\\compositing\\foo.html'])
     50        self.assertEqual(
     51            find_files._normalize(
     52                filesystem,
     53                "c:\\foo",
     54                ['fast/html', 'fast/canvas/*', 'compositing/foo.html'],
     55            ),
     56            [
     57                'c:\\foo\\fast\\html',
     58                'c:\\foo\\fast\\canvas\\*',
     59                'c:\\foo\\compositing\\foo.html',
     60            ],
     61        )
    5062
    5163    def test_mocked_win(self):
     
    6173            return
    6274        self.assert_filesystem_normalizes(FileSystem())
     75
     76
     77class TestFindFiles(unittest.TestCase):
     78    def test_directory_sort_key(self):
     79        filenames = [chr(o) for o in range(ord("a"), ord("z") + 1)]
     80        fs = MockFileSystem(
     81            files={c: "" for c in random.sample(filenames, len(filenames))}
     82        )
     83        self.assertEqual(
     84            list(find_files.find(fs, "", directory_sort_key=lambda x: x)),
     85            sorted(filenames),
     86        )
     87
     88    def test_directory_sort_key_with_paths(self):
     89        filenames = ["/".join(i) for i in itertools.product("abcde", "12345")]
     90        fs = MockFileSystem(
     91            files={c: "" for c in random.sample(filenames, len(filenames))}
     92        )
     93
     94        test_subset = random.sample("abcde", 3)
     95        self.assertEqual(
     96            list(
     97                find_files.find(
     98                    fs,
     99                    "",
     100                    paths=[i + "/*" for i in test_subset],
     101                    directory_sort_key=lambda x: x,
     102                )
     103            ),
     104            ["/".join(i) for i in itertools.product(test_subset, "12345")],
     105        )
Note: See TracChangeset for help on using the changeset viewer.