Changeset 90789 in webkit


Ignore:
Timestamp:
Jul 11, 2011 3:48:15 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

Convert json_results_generator.py to output version 4 JSON.
https://bugs.webkit.org/show_bug.cgi?id=60869

Patch by Alice Boxhall <aboxhall@chromium.org> on 2011-07-11
Reviewed by Ojan Vafai.

  • Scripts/webkitpy/layout_tests/layout_package/json_layout_results_generator.py:
  • Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py:
  • Scripts/webkitpy/layout_tests/layout_package/json_results_generator_unittest.py:
Location:
trunk/Tools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r90786 r90789  
     12011-07-11  Alice Boxhall  <aboxhall@chromium.org>
     2
     3        Convert json_results_generator.py to output version 4 JSON.
     4        https://bugs.webkit.org/show_bug.cgi?id=60869
     5
     6        Reviewed by Ojan Vafai.
     7
     8        * Scripts/webkitpy/layout_tests/layout_package/json_layout_results_generator.py:
     9        * Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py:
     10        * Scripts/webkitpy/layout_tests/layout_package/json_results_generator_unittest.py:
     11
    1122011-07-11  Martin Robinson  <mrobinson@igalia.com>
    213
  • trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/json_layout_results_generator.py

    r90532 r90789  
    126126
    127127    # override
    128     def _convert_json_to_current_version(self, results_json):
    129         archive_version = None
    130         if self.VERSION_KEY in results_json:
    131             archive_version = results_json[self.VERSION_KEY]
    132 
    133         super(JSONLayoutResultsGenerator,
    134               self)._convert_json_to_current_version(results_json)
    135 
    136         # version 2->3
    137         if archive_version == 2:
    138             for results_for_builder in results_json.itervalues():
    139                 try:
    140                     test_results = results_for_builder[self.TESTS]
    141                 except:
    142                     continue
    143 
    144             for test in test_results:
    145                 # Make sure all paths are relative
    146                 test_path = self._get_path_relative_to_layout_test_root(test)
    147                 if test_path != test:
    148                     test_results[test_path] = test_results[test]
    149                     del test_results[test]
    150 
    151     # override
    152128    def _insert_failure_summaries(self, results_for_builder):
    153129        summary = self._result_summary
  • trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py

    r90534 r90789  
    6767    filesystem.write_text_file(file_path, json_string)
    6868
     69
     70def convert_trie_to_flat_paths(trie, prefix=None):
     71    """Converts the directory structure in the given trie to flat paths, prepending a prefix to each."""
     72    result = {}
     73    for name, data in trie.iteritems():
     74        if prefix:
     75            name = prefix + "/" + name
     76
     77        if len(data) and not "results" in data:
     78            result.update(convert_trie_to_flat_paths(data, name))
     79        else:
     80            result[name] = data
     81
     82    return result
     83
     84
     85def add_path_to_trie(path, value, trie):
     86    """Inserts a single flat directory path and associated value into a directory trie structure."""
     87    if not "/" in path:
     88        trie[path] = value
     89        return
     90
     91    directory, slash, rest = path.partition("/")
     92    if not directory in trie:
     93        trie[directory] = {}
     94    add_path_to_trie(rest, value, trie[directory])
     95
    6996def test_timings_trie(port, individual_test_timings):
    7097    """Breaks a test name into chunks by directory and puts the test time as a value in the lowest part, e.g.
     
    84111        test = test_result.test_name
    85112
    86         parts = test.split('/')
    87         current_map = trie
    88         for i, part in enumerate(parts):
    89             if i == (len(parts) - 1):
    90                 current_map[part] = int(1000 * test_result.test_run_time)
    91                 break
    92 
    93             if part not in current_map:
    94                 current_map[part] = {}
    95             current_map = current_map[part]
     113        add_path_to_trie(test, int(1000 * test_result.test_run_time), trie)
     114
    96115    return trie
    97116
     
    148167                        TestResult.FLAKY: FLAKY_RESULT}
    149168
    150     VERSION = 3
     169    VERSION = 4
    151170    VERSION_KEY = "version"
    152171    RESULTS = "results"
     
    266285        tests = results_for_builder[self.TESTS]
    267286        all_failing_tests = self._get_failed_test_names()
    268         all_failing_tests.update(tests.iterkeys())
     287        all_failing_tests.update(convert_trie_to_flat_paths(tests))
     288
    269289        for test in all_failing_tests:
    270290            self._insert_test_time_and_result(test, tests)
     
    517537        time = self._get_test_timing(test_name)
    518538
    519         if test_name not in tests:
    520             tests[test_name] = self._create_results_and_times_json()
    521 
    522         thisTest = tests[test_name]
    523         if self.RESULTS in thisTest:
    524             self._insert_item_run_length_encoded(result, thisTest[self.RESULTS])
    525         else:
    526             thisTest[self.RESULTS] = [[1, result]]
    527 
    528         if self.TIMES in thisTest:
    529             self._insert_item_run_length_encoded(time, thisTest[self.TIMES])
    530         else:
    531             thisTest[self.TIMES] = [[1, time]]
     539        this_test = tests
     540        for segment in test_name.split("/"):
     541            if segment not in this_test:
     542                this_test[segment] = {}
     543            this_test = this_test[segment]
     544
     545        if not len(this_test):
     546            self._populate_results_and_times_json(this_test)
     547
     548        if self.RESULTS in this_test:
     549            self._insert_item_run_length_encoded(result, this_test[self.RESULTS])
     550        else:
     551            this_test[self.RESULTS] = [[1, result]]
     552
     553        if self.TIMES in this_test:
     554            self._insert_item_run_length_encoded(time, this_test[self.TIMES])
     555        else:
     556            this_test[self.TIMES] = [[1, time]]
    532557
    533558    def _convert_json_to_current_version(self, results_json):
     
    535560        current version and adds in the new version number.
    536561        """
    537         if (self.VERSION_KEY in results_json and
    538             results_json[self.VERSION_KEY] == self.VERSION):
     562        if self.VERSION_KEY in results_json:
     563            archive_version = results_json[self.VERSION_KEY]
     564            if archive_version == self.VERSION:
     565                return
     566        else:
     567            archive_version = 3
     568
     569        # version 3->4
     570        if archive_version == 3:
     571            num_results = len(results_json.values())
     572            for builder, results in results_json.iteritems():
     573                self._convert_tests_to_trie(results)
     574
     575        results_json[self.VERSION_KEY] = self.VERSION
     576
     577    def _convert_tests_to_trie(self, results):
     578        if not self.TESTS in results:
    539579            return
    540580
    541         results_json[self.VERSION_KEY] = self.VERSION
    542 
    543     def _create_results_and_times_json(self):
    544         results_and_times = {}
     581        test_results = results[self.TESTS]
     582        test_results_trie = {}
     583        for test in test_results.iterkeys():
     584            single_test_result = test_results[test]
     585            add_path_to_trie(test, single_test_result, test_results_trie)
     586
     587        results[self.TESTS] = test_results_trie
     588
     589    def _populate_results_and_times_json(self, results_and_times):
    545590        results_and_times[self.RESULTS] = []
    546591        results_and_times[self.TIMES] = []
  • trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator_unittest.py

    r90532 r90789  
    156156            tests = buildinfo[JRG.TESTS]
    157157            for test_name in failed_count_map.iterkeys():
    158                 self.assertTrue(test_name in tests)
    159                 test = tests[test_name]
     158                test = self._find_test_in_trie(test_name, tests)
    160159
    161160                failed = 0
     
    173172        if fixable_count:
    174173            self.assertEqual(sum(buildinfo[JRG.FIXABLE_COUNT]), fixable_count)
     174
     175    def _find_test_in_trie(self, path, trie):
     176        nodes = path.split("/")
     177        sub_trie = trie
     178        for node in nodes:
     179            self.assertTrue(node in sub_trie)
     180            sub_trie = sub_trie[node]
     181        return sub_trie
    175182
    176183    def test_json_generation(self):
     
    196203            ['FLAKY_B', 'DISABLED_C', 'FAILS_D'],
    197204            ['A', 'FLAKY_E'])
     205
     206    def test_hierarchical_json_generation(self):
     207        # FIXME: Re-work tests to be more comprehensible and comprehensive.
     208        self._test_json_generation(['foo/A'], ['foo/B', 'bar/C'])
    198209
    199210    def test_test_timings_trie(self):
Note: See TracChangeset for help on using the changeset viewer.