Title: [87078] trunk/Tools
Revision
87078
Author
[email protected]
Date
2011-05-23 10:28:34 -0700 (Mon, 23 May 2011)

Log Message

2011-05-23  Alice Boxhall  <[email protected]>

        Reviewed by Ojan Vafai.

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

        * 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:

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (87077 => 87078)


--- trunk/Tools/ChangeLog	2011-05-23 17:15:25 UTC (rev 87077)
+++ trunk/Tools/ChangeLog	2011-05-23 17:28:34 UTC (rev 87078)
@@ -1,3 +1,14 @@
+2011-05-23  Alice Boxhall  <[email protected]>
+
+        Reviewed by Ojan Vafai.
+
+        Convert json_results_generator.py to output version 4 JSON.
+        https://bugs.webkit.org/show_bug.cgi?id=60869
+
+        * 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:
+
 2011-05-23  Patrick Gansterer  <[email protected]>
 
         Reviewed by Adam Barth.

Modified: trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/json_layout_results_generator.py (87077 => 87078)


--- trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/json_layout_results_generator.py	2011-05-23 17:15:25 UTC (rev 87077)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/json_layout_results_generator.py	2011-05-23 17:28:34 UTC (rev 87078)
@@ -130,30 +130,6 @@
         return self._get_modifier_char(test_name)
 
     # override
-    def _convert_json_to_current_version(self, results_json):
-        archive_version = None
-        if self.VERSION_KEY in results_json:
-            archive_version = results_json[self.VERSION_KEY]
-
-        super(JSONLayoutResultsGenerator,
-              self)._convert_json_to_current_version(results_json)
-
-        # version 2->3
-        if archive_version == 2:
-            for results_for_builder in results_json.itervalues():
-                try:
-                    test_results = results_for_builder[self.TESTS]
-                except:
-                    continue
-
-            for test in test_results:
-                # Make sure all paths are relative
-                test_path = self._get_path_relative_to_layout_test_root(test)
-                if test_path != test:
-                    test_results[test_path] = test_results[test]
-                    del test_results[test]
-
-    # override
     def _insert_failure_summaries(self, results_for_builder):
         summary = self._result_summary
 

Modified: trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py (87077 => 87078)


--- trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py	2011-05-23 17:15:25 UTC (rev 87077)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py	2011-05-23 17:28:34 UTC (rev 87078)
@@ -67,6 +67,49 @@
     json_string = _JSON_PREFIX + json_data + _JSON_SUFFIX
     filesystem.write_text_file(file_path, json_string)
 
+
+def convert_trie_to_flat_paths(trie, prefix=None):
+    """Flattens a trie directory structure into a flat structure.
+
+    Args:
+        trie: trie structure.
+        prefix: aleady-computed path to prepend to the eventual path, if any.
+
+    Returns:
+        The flattened directory structure.
+    """
+    result = {}
+    for name, data in trie.iteritems():
+        if prefix:
+            fullname = prefix + "/" + name
+        else:
+            fullname = name
+
+        if not isinstance(data, dict) or not len(data) or "results" in data:
+            result[fullname] = data
+        else:
+            result.update(convert_trie_to_flat_paths(data, fullname))
+
+    return result
+
+
+def add_path_to_trie(path, value, trie):
+    """Inserts a single flat path key and value into a trie structure.
+
+    Args:
+        path: the path to parse.
+        value: the data value to insert into the trie.
+        trie: the trie into which to insert the path and value.
+    """
+    if not "/" in path:
+        trie[path] = value
+        return
+
+    directory, slash, rest = path.partition("/")
+    if not directory in trie:
+        trie[directory] = {}
+    add_path_to_trie(rest, value, trie[directory])
+
 def test_timings_trie(port, individual_test_timings):
     """Breaks a filename into chunks by directory and puts the test time as a value in the lowest part, e.g.
     foo/bar/baz.html: 1ms
@@ -88,16 +131,8 @@
             # FIXME: Handle this better. Non-layout tests shouldn't be relativized.
             test = test_result.filename
 
-        parts = test.split('/')
-        current_map = trie
-        for i, part in enumerate(parts):
-            if i == (len(parts) - 1):
-                current_map[part] = int(1000 * test_result.test_run_time)
-                break
+        add_path_to_trie(test, int(1000 * test_result.test_run_time), trie)
 
-            if part not in current_map:
-                current_map[part] = {}
-            current_map = current_map[part]
     return trie
 
 # FIXME: We already have a TestResult class in test_results.py
@@ -153,7 +188,7 @@
                         TestResult.FAILS: FAIL_RESULT,
                         TestResult.FLAKY: FLAKY_RESULT}
 
-    VERSION = 3
+    VERSION = 4
     VERSION_KEY = "version"
     RESULTS = "results"
     TIMES = "times"
@@ -271,7 +306,8 @@
         # Update the all failing tests with result type and time.
         tests = results_for_builder[self.TESTS]
         all_failing_tests = self._get_failed_test_names()
-        all_failing_tests.update(tests.iterkeys())
+        all_failing_tests.update(convert_trie_to_flat_paths(tests))
+
         for test in all_failing_tests:
             self._insert_test_time_and_result(test, tests)
 
@@ -512,6 +548,7 @@
             int(time.time()),
             self.TIME)
 
+
     def _insert_test_time_and_result(self, test_name, tests):
         """ Insert a test item with its results to the given tests dictionary.
 
@@ -522,10 +559,15 @@
         result = self._get_result_char(test_name)
         time = self._get_test_timing(test_name)
 
-        if test_name not in tests:
-            tests[test_name] = self._create_results_and_times_json()
+        thisTest = tests
+        for segment in test_name.split("/"):
+            if segment not in thisTest:
+                thisTest[segment] = {}
+            thisTest = thisTest[segment]
 
-        thisTest = tests[test_name]
+        if not len(thisTest):
+            self._populate_results_and_times_json(thisTest)
+
         if self.RESULTS in thisTest:
             self._insert_item_run_length_encoded(result, thisTest[self.RESULTS])
         else:
@@ -540,14 +582,32 @@
         """If the JSON does not match the current version, converts it to the
         current version and adds in the new version number.
         """
-        if (self.VERSION_KEY in results_json and
-            results_json[self.VERSION_KEY] == self.VERSION):
-            return
+        if self.VERSION_KEY in results_json:
+            archive_version = results_json[self.VERSION_KEY]
+            if archive_version == self.VERSION:
+                return
+        else:
+            archive_version = 3
 
+        # version 3->4
+        if archive_version == 3:
+            num_results = len(results_json.values())
+            for builder, results in results_json.iteritems():
+                if not self.TESTS in results:
+                    continue
+
+                test_results = results[self.TESTS]
+                test_results_trie = {}
+                for test in test_results.iterkeys():
+                    test_path = self._get_path_relative_to_layout_test_root(test)
+                    single_test_result = test_results[test]
+                    add_path_to_trie(test_path, single_test_result, test_results_trie)
+
+                results[self.TESTS] = test_results_trie
+
         results_json[self.VERSION_KEY] = self.VERSION
 
-    def _create_results_and_times_json(self):
-        results_and_times = {}
+    def _populate_results_and_times_json(self, results_and_times):
         results_and_times[self.RESULTS] = []
         results_and_times[self.TIMES] = []
         return results_and_times

Modified: trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator_unittest.py (87077 => 87078)


--- trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator_unittest.py	2011-05-23 17:15:25 UTC (rev 87077)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator_unittest.py	2011-05-23 17:28:34 UTC (rev 87078)
@@ -156,8 +156,7 @@
         if failed_count_map:
             tests = buildinfo[JRG.TESTS]
             for test_name in failed_count_map.iterkeys():
-                self.assertTrue(test_name in tests)
-                test = tests[test_name]
+                test = self._find_test_in_trie(test_name, tests)
 
                 failed = 0
                 for result in test[JRG.RESULTS]:
@@ -174,6 +173,14 @@
         if fixable_count:
             self.assertEqual(sum(buildinfo[JRG.FIXABLE_COUNT]), fixable_count)
 
+    def _find_test_in_trie(self, path, trie):
+        sub_trie = trie
+        nodes = path.split("/")
+        for node in nodes:
+            self.assertTrue(node in sub_trie)
+            sub_trie = sub_trie[node]
+        return sub_trie
+
     def test_json_generation(self):
         self._test_json_generation([], [])
         self._test_json_generation(['A1', 'B1'], [])
@@ -197,6 +204,10 @@
             ['FLAKY_B', 'DISABLED_C', 'FAILS_D'],
             ['A', 'FLAKY_E'])
 
+    def test_hierarchical_json_generation(self):
+        # FIXME(aboxhall): re-work tests to be more comprehensible and comprehensive.
+        self._test_json_generation(['foo/A'], ['foo/B', 'bar/C'])
+
     def test_test_timings_trie(self):
         test_port = test.TestPort()
         individual_test_timings = []
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to