|
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 |
"""Converts the directory structure in the given trie to flat paths, prepending a prefix to each.""" |
| 73 |
result = {} |
| 74 |
for name, data in trie.iteritems(): |
| 75 |
if prefix: |
| 76 |
name = prefix + "/" + name |
| 77 |
|
| 78 |
if not "results" in data: |
| 79 |
result.update(convert_trie_to_flat_paths(data, name)) |
| 80 |
else: |
| 81 |
result[name] = data |
| 82 |
|
| 83 |
return result |
| 84 |
|
| 85 |
|
| 86 |
def add_path_to_trie(path, value, trie): |
| 87 |
"""Inserts a single flat directory path and associated value into a directory trie structure.""" |
| 88 |
if not "/" in path: |
| 89 |
trie[path] = value |
| 90 |
return |
| 91 |
|
| 92 |
directory, slash, rest = path.partition("/") |
| 93 |
if not directory in trie: |
| 94 |
trie[directory] = {} |
| 95 |
add_path_to_trie(rest, value, trie[directory]) |
| 96 |
|
| 97 |
|
| 98 |
def convert_trie_to_flat_paths(trie, prefix=None): |
| 99 |
"""Converts the directory structure in the given trie to flat paths, prepending a prefix to each.""" |
| 100 |
result = {} |
| 101 |
for name, data in trie.iteritems(): |
| 102 |
if prefix: |
| 103 |
name = prefix + "/" + name |
| 104 |
|
| 105 |
if not "results" in data: |
| 106 |
result.update(convert_trie_to_flat_paths(data, name)) |
| 107 |
else: |
| 108 |
result[name] = data |
| 109 |
|
| 110 |
return result |
| 111 |
|
| 112 |
|
| 113 |
def add_path_to_trie(path, value, trie): |
| 114 |
"""Inserts a single flat directory path and associated value into a directory trie structure.""" |
| 115 |
if not "/" in path: |
| 116 |
trie[path] = value |
| 117 |
return |
| 118 |
|
| 119 |
directory, slash, rest = path.partition("/") |
| 120 |
if not directory in trie: |
| 121 |
trie[directory] = {} |
| 122 |
add_path_to_trie(rest, value, trie[directory]) |
| 123 |
|
| 70 |
def test_timings_trie(port, individual_test_timings): |
124 |
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. |
125 |
"""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 |
126 |
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. |
142 |
# FIXME: Handle this better. Non-layout tests shouldn't be relativized. |
| 89 |
test = test_result.filename |
143 |
test = test_result.filename |
| 90 |
|
144 |
|
| 91 |
parts = test.split('/') |
145 |
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 |
|
146 |
|
| 98 |
if part not in current_map: |
|
|
| 99 |
current_map[part] = {} |
| 100 |
current_map = current_map[part] |
| 101 |
return trie |
147 |
return trie |
| 102 |
|
148 |
|
| 103 |
# FIXME: We already have a TestResult class in test_results.py |
149 |
# 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, |
199 |
TestResult.FAILS: FAIL_RESULT, |
| 154 |
TestResult.FLAKY: FLAKY_RESULT} |
200 |
TestResult.FLAKY: FLAKY_RESULT} |
| 155 |
|
201 |
|
| 156 |
VERSION = 3 |
202 |
VERSION = 4 |
| 157 |
VERSION_KEY = "version" |
203 |
VERSION_KEY = "version" |
| 158 |
RESULTS = "results" |
204 |
RESULTS = "results" |
| 159 |
TIMES = "times" |
205 |
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. |
317 |
# Update the all failing tests with result type and time. |
| 272 |
tests = results_for_builder[self.TESTS] |
318 |
tests = results_for_builder[self.TESTS] |
| 273 |
all_failing_tests = self._get_failed_test_names() |
319 |
all_failing_tests = self._get_failed_test_names() |
| 274 |
all_failing_tests.update(tests.iterkeys()) |
320 |
all_failing_tests.update(convert_trie_to_flat_paths(tests)) |
|
|
321 |
|
| 275 |
for test in all_failing_tests: |
322 |
for test in all_failing_tests: |
| 276 |
self._insert_test_time_and_result(test, tests) |
323 |
self._insert_test_time_and_result(test, tests) |
| 277 |
|
324 |
|
|
Lines 512-517
class JSONResultsGeneratorBase(object):
a/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py_sec5
|
| 512 |
int(time.time()), |
559 |
int(time.time()), |
| 513 |
self.TIME) |
560 |
self.TIME) |
| 514 |
|
561 |
|
|
|
562 |
|
| 563 |
|
| 515 |
def _insert_test_time_and_result(self, test_name, tests): |
564 |
def _insert_test_time_and_result(self, test_name, tests): |
| 516 |
""" Insert a test item with its results to the given tests dictionary. |
565 |
""" Insert a test item with its results to the given tests dictionary. |
| 517 |
|
566 |
|
|
Lines 522-553
class JSONResultsGeneratorBase(object):
a/Tools/Scripts/webkitpy/layout_tests/layout_package/json_results_generator.py_sec6
|
| 522 |
result = self._get_result_char(test_name) |
571 |
result = self._get_result_char(test_name) |
| 523 |
time = self._get_test_timing(test_name) |
572 |
time = self._get_test_timing(test_name) |
| 524 |
|
573 |
|
| 525 |
if test_name not in tests: |
574 |
this_test = tests |
| 526 |
tests[test_name] = self._create_results_and_times_json() |
575 |
for segment in test_name.split("/"): |
|
|
576 |
if segment not in this_test: |
| 577 |
this_test[segment] = {} |
| 578 |
this_test = this_test[segment] |
| 579 |
|
| 580 |
if not len(this_test): |
| 581 |
self._populate_results_and_times_json(this_test) |
| 527 |
|
582 |
|
| 528 |
thisTest = tests[test_name] |
583 |
if self.RESULTS in this_test: |
| 529 |
if self.RESULTS in thisTest: |
584 |
self._insert_item_run_length_encoded(result, this_test[self.RESULTS]) |
| 530 |
self._insert_item_run_length_encoded(result, thisTest[self.RESULTS]) |
|
|
| 531 |
else: |
585 |
else: |
| 532 |
thisTest[self.RESULTS] = [[1, result]] |
586 |
this_test[self.RESULTS] = [[1, result]] |
| 533 |
|
587 |
|
| 534 |
if self.TIMES in thisTest: |
588 |
if self.TIMES in this_test: |
| 535 |
self._insert_item_run_length_encoded(time, thisTest[self.TIMES]) |
589 |
self._insert_item_run_length_encoded(time, this_test[self.TIMES]) |
| 536 |
else: |
590 |
else: |
| 537 |
thisTest[self.TIMES] = [[1, time]] |
591 |
this_test[self.TIMES] = [[1, time]] |
| 538 |
|
592 |
|
| 539 |
def _convert_json_to_current_version(self, results_json): |
593 |
def _convert_json_to_current_version(self, results_json): |
| 540 |
"""If the JSON does not match the current version, converts it to the |
594 |
"""If the JSON does not match the current version, converts it to the |
| 541 |
current version and adds in the new version number. |
595 |
current version and adds in the new version number. |
| 542 |
""" |
596 |
""" |
| 543 |
if (self.VERSION_KEY in results_json and |
597 |
if self.VERSION_KEY in results_json: |
| 544 |
results_json[self.VERSION_KEY] == self.VERSION): |
598 |
archive_version = results_json[self.VERSION_KEY] |
| 545 |
return |
599 |
if archive_version == self.VERSION: |
|
|
600 |
return |
| 601 |
else: |
| 602 |
archive_version = 3 |
| 603 |
|
| 604 |
# version 3->4 |
| 605 |
if archive_version == 3: |
| 606 |
num_results = len(results_json.values()) |
| 607 |
for builder, results in results_json.iteritems(): |
| 608 |
self._convert_tests_to_trie(results) |
| 546 |
|
609 |
|
| 547 |
results_json[self.VERSION_KEY] = self.VERSION |
610 |
results_json[self.VERSION_KEY] = self.VERSION |
| 548 |
|
611 |
|
| 549 |
def _create_results_and_times_json(self): |
612 |
def _convert_tests_to_trie(self, results): |
| 550 |
results_and_times = {} |
613 |
if not self.TESTS in results: |
|
|
614 |
return |
| 615 |
|
| 616 |
test_results = results[self.TESTS] |
| 617 |
test_results_trie = {} |
| 618 |
for test in test_results.iterkeys(): |
| 619 |
single_test_result = test_results[test] |
| 620 |
add_path_to_trie(test, single_test_result, test_results_trie) |
| 621 |
|
| 622 |
results[self.TESTS] = test_results_trie |
| 623 |
|
| 624 |
def _populate_results_and_times_json(self, results_and_times): |
| 551 |
results_and_times[self.RESULTS] = [] |
625 |
results_and_times[self.RESULTS] = [] |
| 552 |
results_and_times[self.TIMES] = [] |
626 |
results_and_times[self.TIMES] = [] |
| 553 |
return results_and_times |
627 |
return results_and_times |