Changeset 91124 in webkit


Ignore:
Timestamp:
Jul 15, 2011 3:49:25 PM (13 years ago)
Author:
Dimitri Glazkov
Message:

Refactor TestExpectationModel to use TestExpectationLine as data item.
https://bugs.webkit.org/show_bug.cgi?id=64635

This is a bit largish in scope. Does the following things:

1) Adds "path" member to TestExpectationLine to hold normalized path to test, computed at parsing,

and changes code that used Port.normalize_test_name to rely on TestExpectationLine.path. As a result, TestExpectationModel no longer
needs to have any port knowledge.

2) Adds "create_passing_expectation" class method to TestExpectationLine to generate a pristine passing expectation out of a test name,

and changes TestExpectations._process_tests_without_expectations to use it, thus eliminating the need for a special API entry point.
Now all expectations are added to the model in the same way!

3) Changes TestExpectationModel's main test index to store a tuple consisting of line number and TestExpectationLine instance.

Reviewed by Adam Barth.

  • Scripts/webkitpy/layout_tests/models/test_expectations.py: Refactored code.
Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r91123 r91124  
     12011-07-15  Dimitri Glazkov  <dglazkov@chromium.org>
     2
     3        Refactor TestExpectationModel to use TestExpectationLine as data item.
     4        https://bugs.webkit.org/show_bug.cgi?id=64635
     5
     6        This is a bit largish in scope. Does the following things:
     7
     8        1) Adds "path" member to TestExpectationLine to hold normalized path to test, computed at parsing,
     9           and changes code that used Port.normalize_test_name to rely on TestExpectationLine.path. As a result, TestExpectationModel no longer
     10           needs to have any port knowledge.
     11
     12        2) Adds "create_passing_expectation" class method to TestExpectationLine to generate a pristine passing expectation out of a test name,
     13           and changes TestExpectations._process_tests_without_expectations to use it, thus eliminating the need for a special API entry point.
     14           Now all expectations are added to the model in the same way!
     15
     16        3) Changes TestExpectationModel's main test index to store a tuple consisting of line number and TestExpectationLine instance.
     17
     18        Reviewed by Adam Barth.
     19
     20        * Scripts/webkitpy/layout_tests/models/test_expectations.py: Refactored code.
     21
    1222011-07-15  Adam Roben  <aroben@apple.com>
    223
  • trunk/Tools/Scripts/webkitpy/layout_tests/models/test_expectations.py

    r91106 r91124  
    193193            return
    194194
    195         if not self._full_test_list:
    196             expectation_line.matching_tests = [expectation_line.name]
    197         else:
    198             expectation_line.matching_tests = self._collect_matching_tests(expectation_line.name)
     195        expectation_line.path = self._port.normalize_test_name(expectation_line.name)
     196        self._collect_matching_tests(expectation_line)
    199197
    200198        expectation_line.parsed_modifiers = [modifier for modifier in expectation_line.modifiers if modifier in TestExpectations.MODIFIERS]
     
    243241        return False
    244242
    245     def _collect_matching_tests(self, test_list_path):
     243    def _collect_matching_tests(self, expectation_line):
    246244        """Convert the test specification to an absolute, normalized
    247245        path and make sure directories end with the OS path separator."""
     
    252250        # files and nodes being categories.
    253251
    254         if self._port.test_isdir(test_list_path):
     252        if not self._full_test_list:
     253            expectation_line.matching_tests = [expectation_line.path]
     254            return
     255
     256        if self._port.test_isdir(expectation_line.path):
    255257            # this is a test category, return all the tests of the category.
    256             test_list_path = self._port.normalize_test_name(test_list_path)
    257 
    258             return [test for test in self._full_test_list if test.startswith(test_list_path)]
     258            expectation_line.matching_tests = [test for test in self._full_test_list if test.startswith(expectation_line.path)]
     259            return
    259260
    260261        # this is a test file, do a quick check if it's in the
    261262        # full test suite.
    262         result = []
    263         if test_list_path in self._full_test_list:
    264             result = [test_list_path, ]
    265         return result
     263        if expectation_line.path in self._full_test_list:
     264            expectation_line.matching_tests.append(expectation_line.path)
    266265
    267266    @classmethod
     
    325324        """Initializes a blank-line equivalent of an expectation."""
    326325        self.name = None
     326        self.path = None
    327327        self.modifiers = []
    328328        self.parsed_modifiers = []
     
    341341        return self.is_malformed() or len(self.warnings) > 0
    342342
    343 # FIXME: Refactor to use TestExpectationLine as data item.
     343    @classmethod
     344    def create_passing_expectation(cls, test):
     345        expectation_line = TestExpectationLine()
     346        expectation_line.name = test
     347        expectation_line.path = test
     348        expectation_line.parsed_expectations = set([PASS])
     349        expectation_line.matching_tests = [test]
     350        return expectation_line
     351
     352
    344353# FIXME: Refactor API to be a proper CRUD.
    345354class TestExpectationsModel:
    346355    """Represents relational store of all expectations and provides CRUD semantics to manage it."""
    347356
    348     def __init__(self, port):
    349         self._port = port
    350 
     357    def __init__(self):
    351358        # Maps a test to its list of expectations.
    352359        self._test_to_expectations = {}
     
    355362        self._test_to_modifiers = {}
    356363
    357         # Maps a test to the base path that it was listed with in the list and
    358         # the number of matches that base path had.
    359         self._test_list_paths = {}
     364        # Maps a test to a tuple of line number and TestExpectationLine instance.
     365        self._test_to_expectation_line = {}
    360366
    361367        # List of tests that are in the overrides file (used for checking for
     
    405411
    406412    def has_test(self, test):
    407         return test in self._test_list_paths
     413        return test in self._test_to_expectation_line
    408414
    409415    def get_expectations(self, test):
    410416        return self._test_to_expectations[test]
    411417
    412     def add_tests(self, lineno, expectation_line, overrides_allowed):
     418    def add_expectation_line(self, lineno, expectation_line, overrides_allowed):
    413419        """Returns a list of errors, encountered while matching modifiers."""
    414420
     
    420426                continue
    421427
    422             self._clear_expectations_for_test(test, expectation_line.name)
    423             self._test_list_paths[test] = (self._port.normalize_test_name(expectation_line.name), expectation_line.num_matches, lineno)
    424             self.add_test(test, expectation_line, overrides_allowed)
    425 
    426     def add_test(self, test, expectation_line, overrides_allowed):
     428            self._clear_expectations_for_test(test, expectation_line)
     429            self._test_to_expectation_line[test] = (expectation_line, lineno)
     430            self._add_test(test, expectation_line, overrides_allowed)
     431
     432    def _add_test(self, test, expectation_line, overrides_allowed):
    427433        """Sets the expected state for a given test.
    428434
     
    462468            self._overridding_tests.add(test)
    463469
    464     def _clear_expectations_for_test(self, test, test_list_path):
     470    def _clear_expectations_for_test(self, test, expectation_line):
    465471        """Remove prexisting expectations for this test.
    466472        This happens if we are seeing a more precise path
     
    474480            self._remove_from_sets(test, self._result_type_to_tests)
    475481
    476         self._test_list_paths[test] = self._port.normalize_test_name(test_list_path)
     482        self._test_to_expectation_line[test] = (expectation_line, 0)
    477483
    478484    def _remove_from_sets(self, test, dict):
     
    497503            return False
    498504
    499         prev_base_path, prev_num_matches, prev_lineno = self._test_list_paths[test]
    500         base_path = self._port.normalize_test_name(expectation_line.name)
    501 
    502         if len(prev_base_path) > len(base_path):
     505        prev_expectation_line, prev_lineno = self._test_to_expectation_line[test]
     506
     507        if len(prev_expectation_line.path) > len(expectation_line.path):
    503508            # The previous path matched more of the test.
    504509            return True
    505510
    506         if len(prev_base_path) < len(base_path):
     511        if len(prev_expectation_line.path) < len(expectation_line.path):
    507512            # This path matches more of the test.
    508513            return False
     
    531536        # to be warnings and return False".
    532537
    533         if prev_num_matches == expectation_line.num_matches:
     538        if prev_expectation_line.num_matches == expectation_line.num_matches:
    534539            expectation_line.errors.append('Duplicate or ambiguous %s.' % expectation_source)
    535540            return True
    536541
    537         if prev_num_matches < expectation_line.num_matches:
     542        if prev_expectation_line.num_matches < expectation_line.num_matches:
    538543            expectation_line.errors.append('More specific entry on line %d overrides line %d' % (lineno, prev_lineno))
    539544            # FIXME: return False if we want more specific to win.
     
    648653        self._test_config = test_config
    649654        self._is_lint_mode = is_lint_mode
    650         self._model = TestExpectationsModel(port)
     655        self._model = TestExpectationsModel()
    651656        self._parser = TestExpectationParser(port, test_config, tests, is_lint_mode)
    652657
     
    761766
    762767    def _process_tests_without_expectations(self):
    763         expectation = TestExpectationLine()
    764         expectation.parsed_expectations = set([PASS])
    765768        if self._full_test_list:
    766769            for test in self._full_test_list:
    767770                if not self._model.has_test(test):
    768                     self._model.add_test(test, expectation, overrides_allowed=False)
     771                    self._model.add_expectation_line(0, TestExpectationLine.create_passing_expectation(test), overrides_allowed=False)
    769772
    770773    def get_expectations_json_for_all_platforms(self):
     
    791794    def _add_expectations(self, expectation_list, overrides_allowed):
    792795        lineno = 0
    793         for expectation in expectation_list:
     796        for expectation_line in expectation_list:
    794797            lineno += 1
    795             expectations = expectation.expectations
    796 
    797             if not expectation.expectations:
     798            if not expectation_line.expectations:
    798799                continue
    799800
    800             self._add_to_all_expectations(expectation.name,
    801                                             " ".join(expectation.modifiers).upper(),
    802                                             " ".join(expectation.expectations).upper())
    803 
    804             self._parser.parse(expectation)
    805             self._model.add_tests(lineno, expectation, overrides_allowed)
     801            self._add_to_all_expectations(expectation_line.name,
     802                                            " ".join(expectation_line.modifiers).upper(),
     803                                            " ".join(expectation_line.expectations).upper())
     804
     805            self._parser.parse(expectation_line)
     806            self._model.add_expectation_line(lineno, expectation_line, overrides_allowed)
    806807
    807808
Note: See TracChangeset for help on using the changeset viewer.