|
Lines 67-72
def write_json(filesystem, json_object, file_path):
a/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py_sec1
|
| 67 |
json_string = _JSON_PREFIX + json_data + _JSON_SUFFIX |
67 |
json_string = _JSON_PREFIX + json_data + _JSON_SUFFIX |
| 68 |
filesystem.write_text_file(file_path, json_string) |
68 |
filesystem.write_text_file(file_path, json_string) |
| 69 |
|
69 |
|
|
|
70 |
|
| 71 |
def convert_trie_to_flat_paths(trie, prefix=None): |
| 72 |
"""Flattens a trie directory structure into a flat structure. |
| 73 |
|
| 74 |
Args: |
| 75 |
trie: trie structure. |
| 76 |
prefix: aleady-computed path to prepend to the eventual path, if any. |
| 77 |
|
| 78 |
Returns: |
| 79 |
The flattened directory structure. |
| 80 |
""" |
| 81 |
result = {} |
| 82 |
for name, data in trie.iteritems(): |
| 83 |
if prefix: |
| 84 |
fullname = prefix + "/" + name |
| 85 |
else: |
| 86 |
fullname = name |
| 87 |
|
| 88 |
if not isinstance(data, dict) or not len(data) or "results" in data: |
| 89 |
result[fullname] = data |
| 90 |
else: |
| 91 |
result.update(convert_trie_to_flat_paths(data, fullname)) |
| 92 |
|
| 93 |
return result |
| 94 |
|
| 95 |
|
| 96 |
def add_path_to_trie(path, value, trie): |
| 97 |
"""Inserts a single flat path key and value into a trie structure. |
| 98 |
|
| 99 |
Args: |
| 100 |
path: the path to parse. |
| 101 |
value: the data value to insert into the trie. |
| 102 |
trie: the trie into which to insert the path and value. |
| 103 |
""" |
| 104 |
if not "/" in path: |
| 105 |
trie[path] = value |
| 106 |
return |
| 107 |
|
| 108 |
directory, slash, rest = path.partition("/") |
| 109 |
if not directory in trie: |
| 110 |
trie[directory] = {} |
| 111 |
add_path_to_trie(rest, value, trie[directory]) |
| 112 |
|
| 70 |
def test_timings_trie(port, individual_test_timings): |
113 |
def test_timings_trie(port, individual_test_timings): |
| 71 |
"""Breaks a filename into chunks by directory and puts the test time as a value in the lowest part, e.g. |
114 |
"""Breaks a filename into chunks by directory and puts the test time as a value in the lowest part, e.g. |
| 72 |
foo/bar/baz.html: 1ms |
115 |
foo/bar/baz.html: 1ms |
|
Lines 88-103
def test_timings_trie(port, individual_test_timings):
a/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py_sec2
|
| 88 |
# FIXME: Handle this better. Non-layout tests shouldn't be relativized. |
131 |
# FIXME: Handle this better. Non-layout tests shouldn't be relativized. |
| 89 |
test = test_result.filename |
132 |
test = test_result.filename |
| 90 |
|
133 |
|
| 91 |
parts = test.split('/') |
134 |
add_path_to_trie(test, int(1000 * test_result.test_run_time), trie) |
| 92 |
current_map = trie |
|
|
| 93 |
for i, part in enumerate(parts): |
| 94 |
if i == (len(parts) - 1): |
| 95 |
current_map[part] = int(1000 * test_result.test_run_time) |
| 96 |
break |
| 97 |
|
135 |
|
| 98 |
if part not in current_map: |
|
|
| 99 |
current_map[part] = {} |
| 100 |
current_map = current_map[part] |
| 101 |
return trie |
136 |
return trie |
| 102 |
|
137 |
|
| 103 |
# FIXME: We already have a TestResult class in test_results.py |
138 |
# FIXME: We already have a TestResult class in test_results.py |
|
Lines 153-159
class JSONResultsGeneratorBase(object):
a/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py_sec3
|
| 153 |
TestResult.FAILS: FAIL_RESULT, |
188 |
TestResult.FAILS: FAIL_RESULT, |
| 154 |
TestResult.FLAKY: FLAKY_RESULT} |
189 |
TestResult.FLAKY: FLAKY_RESULT} |
| 155 |
|
190 |
|
| 156 |
VERSION = 3 |
191 |
VERSION = 4 |
| 157 |
VERSION_KEY = "version" |
192 |
VERSION_KEY = "version" |
| 158 |
RESULTS = "results" |
193 |
RESULTS = "results" |
| 159 |
TIMES = "times" |
194 |
TIMES = "times" |
|
Lines 271-277
class JSONResultsGeneratorBase(object):
a/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py_sec4
|
| 271 |
# Update the all failing tests with result type and time. |
306 |
# Update the all failing tests with result type and time. |
| 272 |
tests = results_for_builder[self.TESTS] |
307 |
tests = results_for_builder[self.TESTS] |
| 273 |
all_failing_tests = self._get_failed_test_names() |
308 |
all_failing_tests = self._get_failed_test_names() |
| 274 |
all_failing_tests.update(tests.iterkeys()) |
309 |
all_failing_tests.update(convert_trie_to_flat_paths(tests)) |
|
|
310 |
|
| 275 |
for test in all_failing_tests: |
311 |
for test in all_failing_tests: |
| 276 |
self._insert_test_time_and_result(test, tests) |
312 |
self._insert_test_time_and_result(test, tests) |
| 277 |
|
313 |
|
|
Lines 512-517
class JSONResultsGeneratorBase(object):
a/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py_sec5
|
| 512 |
int(time.time()), |
548 |
int(time.time()), |
| 513 |
self.TIME) |
549 |
self.TIME) |
| 514 |
|
550 |
|
|
|
551 |
|
| 515 |
def _insert_test_time_and_result(self, test_name, tests): |
552 |
def _insert_test_time_and_result(self, test_name, tests): |
| 516 |
""" Insert a test item with its results to the given tests dictionary. |
553 |
""" Insert a test item with its results to the given tests dictionary. |
| 517 |
|
554 |
|
|
Lines 522-531
class JSONResultsGeneratorBase(object):
a/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py_sec6
|
| 522 |
result = self._get_result_char(test_name) |
559 |
result = self._get_result_char(test_name) |
| 523 |
time = self._get_test_timing(test_name) |
560 |
time = self._get_test_timing(test_name) |
| 524 |
|
561 |
|
| 525 |
if test_name not in tests: |
562 |
thisTest = tests |
| 526 |
tests[test_name] = self._create_results_and_times_json() |
563 |
for segment in test_name.split("/"): |
|
|
564 |
if segment not in thisTest: |
| 565 |
thisTest[segment] = {} |
| 566 |
thisTest = thisTest[segment] |
| 567 |
|
| 568 |
if not len(thisTest): |
| 569 |
self._populate_results_and_times_json(thisTest) |
| 527 |
|
570 |
|
| 528 |
thisTest = tests[test_name] |
|
|
| 529 |
if self.RESULTS in thisTest: |
571 |
if self.RESULTS in thisTest: |
| 530 |
self._insert_item_run_length_encoded(result, thisTest[self.RESULTS]) |
572 |
self._insert_item_run_length_encoded(result, thisTest[self.RESULTS]) |
| 531 |
else: |
573 |
else: |
|
Lines 540-553
class JSONResultsGeneratorBase(object):
a/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py_sec7
|
| 540 |
"""If the JSON does not match the current version, converts it to the |
582 |
"""If the JSON does not match the current version, converts it to the |
| 541 |
current version and adds in the new version number. |
583 |
current version and adds in the new version number. |
| 542 |
""" |
584 |
""" |
| 543 |
if (self.VERSION_KEY in results_json and |
585 |
if self.VERSION_KEY in results_json: |
| 544 |
results_json[self.VERSION_KEY] == self.VERSION): |
586 |
archive_version = results_json[self.VERSION_KEY] |
| 545 |
return |
587 |
if archive_version == self.VERSION: |
|
|
588 |
return |
| 589 |
else: |
| 590 |
archive_version = 3 |
| 591 |
|
| 592 |
# version 3->4 |
| 593 |
if archive_version == 3: |
| 594 |
num_results = len(results_json.values()) |
| 595 |
for builder, results in results_json.iteritems(): |
| 596 |
self._convert_tests_to_trie(results) |
| 546 |
|
597 |
|
| 547 |
results_json[self.VERSION_KEY] = self.VERSION |
598 |
results_json[self.VERSION_KEY] = self.VERSION |
| 548 |
|
599 |
|
| 549 |
def _create_results_and_times_json(self): |
600 |
def _convert_tests_to_trie(self, results): |
| 550 |
results_and_times = {} |
601 |
if not self.TESTS in results: |
|
|
602 |
return |
| 603 |
|
| 604 |
test_results = results[self.TESTS] |
| 605 |
test_results_trie = {} |
| 606 |
for test in test_results.iterkeys(): |
| 607 |
test_path = self._get_path_relative_to_layout_test_root(test) |
| 608 |
single_test_result = test_results[test] |
| 609 |
add_path_to_trie(test_path, single_test_result, test_results_trie) |
| 610 |
|
| 611 |
results[self.TESTS] = test_results_trie |
| 612 |
|
| 613 |
def _populate_results_and_times_json(self, results_and_times): |
| 551 |
results_and_times[self.RESULTS] = [] |
614 |
results_and_times[self.RESULTS] = [] |
| 552 |
results_and_times[self.TIMES] = [] |
615 |
results_and_times[self.TIMES] = [] |
| 553 |
return results_and_times |
616 |
return results_and_times |