| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """A script to modify TestExpectations lines based layout test failures in try j
obs. | 5 """A script to modify TestExpectations lines based layout test failures in try j
obs. |
| 6 | 6 |
| 7 This script outputs a list of test expectation lines to add to a 'TestExpectatio
ns' file | 7 This script outputs a list of test expectation lines to add to a 'TestExpectatio
ns' file |
| 8 by retrieving the try job results for the current CL. | 8 by retrieving the try job results for the current CL. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 import logging | 11 import logging |
| 12 | 12 |
| 13 from webkitpy.common.net import rietveld |
| 13 from webkitpy.common.net.buildbot import BuildBot | 14 from webkitpy.common.net.buildbot import BuildBot |
| 14 from webkitpy.common.net import rietveld | 15 from webkitpy.common.webkit_finder import WebKitFinder |
| 15 | 16 from webkitpy.w3c.test_parser import TestParser |
| 16 | 17 |
| 17 _log = logging.getLogger(__name__) | 18 _log = logging.getLogger(__name__) |
| 18 | 19 |
| 19 | 20 |
| 20 def main(host, port): | 21 def main(host, port): |
| 21 expectations_file = port.path_to_generic_test_expectations_file() | 22 expectations_file = port.path_to_generic_test_expectations_file() |
| 22 expectations_line_adder = W3CExpectationsLineAdder(host) | 23 expectations_line_adder = W3CExpectationsLineAdder(host) |
| 23 issue_number = expectations_line_adder.get_issue_number() | 24 issue_number = expectations_line_adder.get_issue_number() |
| 24 try_bots = expectations_line_adder.get_try_bots() | 25 try_bots = expectations_line_adder.get_try_bots() |
| 25 try_jobs = rietveld.latest_try_jobs(issue_number, try_bots, host.web) | 26 try_jobs = rietveld.latest_try_jobs(issue_number, try_bots, host.web) |
| 26 test_expectations = {} | 27 test_expectations = {} |
| 27 if not try_jobs: | 28 if not try_jobs: |
| 28 print 'No Try Job information was collected.' | 29 print 'No Try Job information was collected.' |
| 29 return 1 | 30 return 1 |
| 30 for job in try_jobs: | 31 for job in try_jobs: |
| 31 platform_results = expectations_line_adder.get_failing_results_dict(Buil
dBot(), job.builder_name, job.build_number) | 32 platform_results = expectations_line_adder.get_failing_results_dict(Buil
dBot(), job.builder_name, job.build_number) |
| 32 test_expectations = expectations_line_adder.merge_dicts(test_expectation
s, platform_results) | 33 test_expectations = expectations_line_adder.merge_dicts(test_expectation
s, platform_results) |
| 33 for test_name, platform_result in test_expectations.iteritems(): | 34 for test_name, platform_result in test_expectations.iteritems(): |
| 34 test_expectations[test_name] = expectations_line_adder.merge_same_valued
_keys(platform_result) | 35 test_expectations[test_name] = expectations_line_adder.merge_same_valued
_keys(platform_result) |
| 36 test_expectations = expectations_line_adder.get_expected_txt_files(test_expe
ctations) |
| 35 test_expectation_lines = expectations_line_adder.create_line_list(test_expec
tations) | 37 test_expectation_lines = expectations_line_adder.create_line_list(test_expec
tations) |
| 36 expectations_line_adder.write_to_test_expectations(host, expectations_file,
test_expectation_lines) | 38 expectations_line_adder.write_to_test_expectations(host, expectations_file,
test_expectation_lines) |
| 37 | 39 |
| 38 | 40 |
| 39 class W3CExpectationsLineAdder(object): | 41 class W3CExpectationsLineAdder(object): |
| 40 | 42 |
| 41 def __init__(self, host): | 43 def __init__(self, host): |
| 42 self._host = host | 44 self._host = host |
| 43 self.filesystem = host.filesystem | 45 self.filesystem = host.filesystem |
| 44 | 46 |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 all_lines += str(line) + '\n' | 262 all_lines += str(line) + '\n' |
| 261 all_lines = all_lines[:-1] | 263 all_lines = all_lines[:-1] |
| 262 if w3c_comment_line_index == -1: | 264 if w3c_comment_line_index == -1: |
| 263 file_contents += '\n%s\n' % comment_line | 265 file_contents += '\n%s\n' % comment_line |
| 264 file_contents += all_lines | 266 file_contents += all_lines |
| 265 else: | 267 else: |
| 266 end_of_comment_line = (file_contents[w3c_comment_line_index:].find('
\n')) + w3c_comment_line_index | 268 end_of_comment_line = (file_contents[w3c_comment_line_index:].find('
\n')) + w3c_comment_line_index |
| 267 new_data = file_contents[: end_of_comment_line + 1] + all_lines + fi
le_contents[end_of_comment_line:] | 269 new_data = file_contents[: end_of_comment_line + 1] + all_lines + fi
le_contents[end_of_comment_line:] |
| 268 file_contents = new_data | 270 file_contents = new_data |
| 269 host.filesystem.write_text_file(path, file_contents) | 271 host.filesystem.write_text_file(path, file_contents) |
| 272 |
| 273 def get_expected_txt_files(self, tests_results): |
| 274 """Gets -expected.txt files. |
| 275 |
| 276 Invokes webkit-patch rebaseline-from-try-jobs in order |
| 277 to download new -expected.txt files for testharness.js |
| 278 tests that did not Crash or Timeout. Then the platform- |
| 279 specific test is removed from the overall failure test dictionary. |
| 280 |
| 281 Args: |
| 282 tests_results: A dictionary that maps test name to platforms to |
| 283 test results. |
| 284 |
| 285 Returns: |
| 286 An updated tests_results dictionary without the platform-specific te
st- |
| 287 harness.js tests that required new baselines to be downloaded from |
| 288 webkit-patch rebaseline-from-try-jobs. |
| 289 """ |
| 290 finder = WebKitFinder(self._host.filesystem) |
| 291 tests = self._host.executive.run_command(['git', 'diff', 'master', '--na
me-only']) |
| 292 for test in tests.splitlines(): |
| 293 if self.is_js_test(finder, test): |
| 294 tests_to_rebaseline, tests_results = self.get_tests_to_rebaselin
e(finder, test, tests_results) |
| 295 if tests_to_rebaseline: |
| 296 webkit_patch = self._host.filesystem.join(finder.chromium_base(), fi
nder.webkit_base(), |
| 297 finder.path_to_script('web
kit-patch')) |
| 298 self._host.executive.run_command(['python', webkit_patch, |
| 299 'rebaseline-from-try-jobs', '-v']
+ tests_to_rebaseline) |
| 300 return tests_results |
| 301 |
| 302 def get_tests_to_rebaseline(self, webkit_finder, test_name, tests_results): |
| 303 tests_to_rebaseline = set() |
| 304 layout_tests_relative_path = self._host.filesystem.relpath(webkit_finder
.layout_tests_dir(), webkit_finder.chromium_base()) |
| 305 test_path = self._host.filesystem.relpath(test_name, layout_tests_relati
ve_path) |
| 306 for platform in tests_results[test_path].keys(): |
| 307 if tests_results[test_path][platform]['actual'] not in ['CRASH', 'TI
MEOUT']: |
| 308 del tests_results[test_path][platform] |
| 309 tests_to_rebaseline.add(test_path) |
| 310 return list(tests_to_rebaseline), tests_results |
| 311 |
| 312 def is_js_test(self, webkit_finder, test_path): |
| 313 absolute_path = self._host.filesystem.join(webkit_finder.chromium_base()
, test_path) |
| 314 test_parser = TestParser(absolute_path, self._host) |
| 315 return test_parser.is_jstest() |
| OLD | NEW |