| OLD | NEW |
| (Empty) | |
| 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import logging |
| 6 import os |
| 7 |
| 8 from layout_package import json_results_generator |
| 9 from layout_package import path_utils |
| 10 from layout_package import test_expectations |
| 11 from layout_package import test_failures |
| 12 |
| 13 class JSONLayoutResultsGenerator(json_results_generator.JSONResultsGenerator): |
| 14 """A JSON results generator for layout tests.""" |
| 15 |
| 16 LAYOUT_TESTS_PATH = "LayoutTests" |
| 17 |
| 18 # Additional JSON fields. |
| 19 WONTFIX = "wontfixCounts" |
| 20 DEFERRED = "deferredCounts" |
| 21 |
| 22 def __init__(self, builder_name, build_name, build_number, |
| 23 results_file_base_path, builder_base_url, |
| 24 test_timings, expectations, result_summary, all_tests): |
| 25 """Modifies the results.json file. Grabs it off the archive directory if it |
| 26 is not found locally. |
| 27 |
| 28 Args: |
| 29 result_summary: ResultsSummary object storing the summary of the test |
| 30 results. |
| 31 (see the comment of JSONResultsGenerator.__init__ for other Args) |
| 32 """ |
| 33 |
| 34 self._builder_name = builder_name |
| 35 self._build_name = build_name |
| 36 self._build_number = build_number |
| 37 self._builder_base_url = builder_base_url |
| 38 self._results_file_path = os.path.join(results_file_base_path, |
| 39 self.RESULTS_FILENAME) |
| 40 self._expectations = expectations |
| 41 |
| 42 # We don't use self._skipped_tests and self._passed_tests as we |
| 43 # override _InsertFailureSummaries. |
| 44 |
| 45 # We want relative paths to LayoutTest root for JSON output. |
| 46 path_to_name = self._GetPathRelativeToLayoutTestRoot |
| 47 self._result_summary = result_summary |
| 48 self._failures = dict( |
| 49 (path_to_name(test), test_failures.DetermineResultType(failures)) |
| 50 for (test, failures) in result_summary.failures.iteritems()) |
| 51 self._all_tests = [path_to_name(test) for test in all_tests] |
| 52 self._test_timings = dict( |
| 53 (path_to_name(test_tuple.filename), test_tuple.test_run_time) |
| 54 for test_tuple in test_timings) |
| 55 |
| 56 self._GenerateJSONOutput() |
| 57 |
| 58 def _GetPathRelativeToLayoutTestRoot(self, test): |
| 59 """Returns the path of the test relative to the layout test root. |
| 60 For example, for: |
| 61 src/third_party/WebKit/LayoutTests/fast/forms/foo.html |
| 62 We would return |
| 63 fast/forms/foo.html |
| 64 """ |
| 65 index = test.find(self.LAYOUT_TESTS_PATH) |
| 66 if index is not -1: |
| 67 index += len(self.LAYOUT_TESTS_PATH) |
| 68 |
| 69 if index is -1: |
| 70 # Already a relative path. |
| 71 relativePath = test |
| 72 else: |
| 73 relativePath = test[index + 1:] |
| 74 |
| 75 # Make sure all paths are unix-style. |
| 76 return relativePath.replace('\\', '/') |
| 77 |
| 78 # override |
| 79 def _ConvertJSONToCurrentVersion(self, results_json): |
| 80 archive_version = None |
| 81 if self.VERSION_KEY in results_json: |
| 82 archive_version = results_json[self.VERSION_KEY] |
| 83 |
| 84 super(JSONLayoutResultsGenerator, self)._ConvertJSONToCurrentVersion( |
| 85 results_json) |
| 86 |
| 87 # version 2->3 |
| 88 if archive_version == 2: |
| 89 for results_for_builder in results_json.itervalues(): |
| 90 try: |
| 91 test_results = results_for_builder[self.TESTS] |
| 92 except: |
| 93 continue |
| 94 |
| 95 for test in test_results: |
| 96 # Make sure all paths are relative |
| 97 test_path = self._GetPathRelativeToLayoutTestRoot(test) |
| 98 if test_path != test: |
| 99 test_results[test_path] = test_results[test] |
| 100 del test_results[test] |
| 101 |
| 102 # override |
| 103 def _InsertFailureSummaries(self, results_for_builder): |
| 104 summary = self._result_summary |
| 105 |
| 106 self._InsertItemIntoRawList(results_for_builder, |
| 107 len((set(summary.failures.keys()) | |
| 108 summary.tests_by_expectation[test_expectations.SKIP]) & |
| 109 summary.tests_by_timeline[test_expectations.NOW]), |
| 110 self.FIXABLE_COUNT) |
| 111 self._InsertItemIntoRawList(results_for_builder, |
| 112 self._GetFailureSummaryEntry(test_expectations.NOW), |
| 113 self.FIXABLE) |
| 114 self._InsertItemIntoRawList(results_for_builder, |
| 115 len(self._expectations.GetTestsWithTimeline(test_expectations.NOW)), |
| 116 self.ALL_FIXABLE_COUNT) |
| 117 self._InsertItemIntoRawList(results_for_builder, |
| 118 self._GetFailureSummaryEntry(test_expectations.DEFER), |
| 119 self.DEFERRED) |
| 120 self._InsertItemIntoRawList(results_for_builder, |
| 121 self._GetFailureSummaryEntry(test_expectations.WONTFIX), |
| 122 self.WONTFIX) |
| 123 |
| 124 # override |
| 125 def _NormalizeResultsJSON(self, test, test_name, tests): |
| 126 super(JSONLayoutResultsGenerator, self)._NormalizeResultsJSON( |
| 127 test, test_name, tests) |
| 128 |
| 129 # Remove tests that don't exist anymore. |
| 130 full_path = os.path.join(path_utils.LayoutTestsDir(), test_name) |
| 131 full_path = os.path.normpath(full_path) |
| 132 if not os.path.exists(full_path): |
| 133 del tests[test_name] |
| 134 |
| 135 def _GetFailureSummaryEntry(self, timeline): |
| 136 """Creates a summary object to insert into the JSON. |
| 137 |
| 138 Args: |
| 139 summary ResultSummary object with test results |
| 140 timeline current test_expectations timeline to build entry for (e.g., |
| 141 test_expectations.NOW, etc.) |
| 142 """ |
| 143 entry = {} |
| 144 summary = self._result_summary |
| 145 timeline_tests = summary.tests_by_timeline[timeline] |
| 146 entry[self.SKIP_RESULT] = len( |
| 147 summary.tests_by_expectation[test_expectations.SKIP] & timeline_tests) |
| 148 entry[self.PASS_RESULT] = len( |
| 149 summary.tests_by_expectation[test_expectations.PASS] & timeline_tests) |
| 150 for failure_type in summary.tests_by_expectation.keys(): |
| 151 if failure_type not in self.FAILURE_TO_CHAR: |
| 152 continue |
| 153 count = len(summary.tests_by_expectation[failure_type] & timeline_tests) |
| 154 entry[self.FAILURE_TO_CHAR[failure_type]] = count |
| 155 return entry |
| OLD | NEW |