OLD | NEW |
1 # Copyright (c) 2011 Google Inc. All rights reserved. | 1 # Copyright (c) 2011 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
11 # in the documentation and/or other materials provided with the | 11 # in the documentation and/or other materials provided with the |
12 # distribution. | 12 # distribution. |
13 # * Neither the name of Google Inc. nor the names of its | 13 # * Neither the name of Google Inc. nor the names of its |
14 # contributors may be used to endorse or promote products derived from | 14 # contributors may be used to endorse or promote products derived from |
15 # this software without specific prior written permission. | 15 # this software without specific prior written permission. |
16 # | 16 # |
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | 28 |
| 29 import os |
29 import optparse | 30 import optparse |
30 from webkitpy.tool.multicommandtool import AbstractDeclarativeCommand | 31 from webkitpy.tool.multicommandtool import AbstractDeclarativeCommand |
31 from webkitpy.layout_tests.layout_package.bot_test_expectations import BotTestEx
pectationsFactory | 32 from webkitpy.layout_tests.layout_package.bot_test_expectations import BotTestEx
pectationsFactory |
32 from webkitpy.layout_tests.models.test_expectations import TestExpectationParser
, TestExpectationsModel, TestExpectations | 33 from webkitpy.layout_tests.models.test_expectations import TestExpectationParser
, TestExpectationsModel, TestExpectations |
| 34 from webkitpy.common.net import sheriff_calendar |
33 | 35 |
34 | 36 |
35 class FlakyTests(AbstractDeclarativeCommand): | 37 class FlakyTests(AbstractDeclarativeCommand): |
36 name = "update-flaky-tests" | 38 name = "update-flaky-tests" |
37 help_text = "Update FlakyTests file from the flakiness dashboard" | 39 help_text = "Update FlakyTests file from the flakiness dashboard" |
38 show_in_main_help = True | 40 show_in_main_help = True |
39 | 41 |
| 42 ALWAYS_CC = [ |
| 43 'ojan@chromium.org', |
| 44 'dpranke@chromium.org', |
| 45 'eseidel@chromium.org', |
| 46 ] |
| 47 |
40 def __init__(self): | 48 def __init__(self): |
41 options = [ | 49 options = [ |
42 optparse.make_option('--upload', action='store_true', | 50 optparse.make_option('--upload', action='store_true', |
43 help='upload the changed FlakyTest file for review'), | 51 help='upload the changed FlakyTest file for review'), |
| 52 optparse.make_option('--reviewers', action='store', |
| 53 help='comma-separated list of reviewers, defaults to blink garde
ners'), |
44 ] | 54 ] |
45 AbstractDeclarativeCommand.__init__(self, options=options) | 55 AbstractDeclarativeCommand.__init__(self, options=options) |
46 | 56 |
47 def execute(self, options, args, tool): | 57 def execute(self, options, args, tool): |
48 port = tool.port_factory.get() | 58 port = tool.port_factory.get() |
49 model = TestExpectationsModel() | 59 model = TestExpectationsModel() |
50 for port_name in tool.port_factory.all_port_names(): | 60 for port_name in tool.port_factory.all_port_names(): |
51 expectations = BotTestExpectationsFactory().expectations_for_port(po
rt_name) | 61 expectations = BotTestExpectationsFactory().expectations_for_port(po
rt_name) |
52 for line in expectations.expectation_lines(only_ignore_very_flaky=Tr
ue): | 62 for line in expectations.expectation_lines(only_ignore_very_flaky=Tr
ue): |
53 model.add_expectation_line(line) | 63 model.add_expectation_line(line) |
54 # FIXME: We need an official API to get all the test names or all test l
ines. | 64 # FIXME: We need an official API to get all the test names or all test l
ines. |
55 lines = model._test_to_expectation_line.values() | 65 lines = model._test_to_expectation_line.values() |
56 lines.sort(key=lambda line: line.path) | 66 lines.sort(key=lambda line: line.path) |
57 # Skip any tests which are mentioned in the dashboard but not in our che
ckout: | 67 # Skip any tests which are mentioned in the dashboard but not in our che
ckout: |
58 fs = tool.filesystem | 68 fs = tool.filesystem |
59 lines = filter(lambda line: fs.exists(fs.join(port.layout_tests_dir(), l
ine.path)), lines) | 69 lines = filter(lambda line: fs.exists(fs.join(port.layout_tests_dir(), l
ine.path)), lines) |
60 flaky_tests_path = fs.join(port.layout_tests_dir(), 'FlakyTests') | 70 flaky_tests_path = fs.join(port.layout_tests_dir(), 'FlakyTests') |
61 # Note: This includes all flaky tests from the dashboard, even ones ment
ioned | 71 # Note: This includes all flaky tests from the dashboard, even ones ment
ioned |
62 # in existing TestExpectations. We could certainly load existing TestExp
ecations | 72 # in existing TestExpectations. We could certainly load existing TestExp
ecations |
63 # and filter accordingly, or update existing TestExpectations instead of
FlakyTests. | 73 # and filter accordingly, or update existing TestExpectations instead of
FlakyTests. |
64 with open(flaky_tests_path, 'w') as flake_file: | 74 with open(flaky_tests_path, 'w') as flake_file: |
65 flake_file.write(TestExpectations.list_to_string(lines)) | 75 flake_file.write(TestExpectations.list_to_string(lines)) |
| 76 print "Updated %s" % flaky_tests_path |
66 | 77 |
67 if not options.upload: | 78 if not options.upload: |
68 return 0 | 79 return 0 |
69 | 80 |
70 files = tool.scm().changed_files() | 81 files = tool.scm().changed_files() |
71 flaky_tests_path = 'LayoutTests/FlakyTests' | 82 flaky_tests_path = 'LayoutTests/FlakyTests' |
72 if flaky_tests_path not in files: | 83 if flaky_tests_path not in files: |
73 print "%s is not changed, not uploading." % flaky_tests_path | 84 print "%s is not changed, not uploading." % flaky_tests_path |
74 return 0 | 85 return 0 |
75 | 86 |
76 commit_message = "Update FlakyTests" | 87 if options.reviewers: |
77 git_cmd = ['git', 'commit', '-m', commit_message, flaky_tests_path] | 88 # FIXME: Could validate these as emails. sheriff_calendar has some c
ode for that. |
78 tool.executive.run_command(git_cmd) | 89 reviewer_emails = options.reviewers.split(',') |
| 90 else: |
| 91 reviewer_emails = sheriff_calendar.current_gardener_emails() |
| 92 if not reviewer_emails: |
| 93 print "No gardener, and --reviewers not specified, not bothering
." |
| 94 return 1 |
79 | 95 |
80 git_cmd = ['git', 'cl', 'upload', '--use-commit-queue', '--send-mail'] | 96 commit_message = """Update FlakyTests to match current flakiness dashboa
rd results |
81 tool.executive.run_command(git_cmd) | 97 |
| 98 Automatically generated using: |
| 99 webkit-patch update-flaky-tests |
| 100 |
| 101 R=%s |
| 102 """ % ','.join(reviewer_emails) |
| 103 |
| 104 git_cmd = ['git', 'commit', '-m', commit_message, |
| 105 fs.join(tool.scm().checkout_root, flaky_tests_path)] |
| 106 tool.executive.run_and_throw_if_fail(git_cmd) |
| 107 |
| 108 # FIXME: There must be a cleaner way to avoid the editor! |
| 109 # Silence the editor. |
| 110 os.environ['EDITOR'] = 'true' |
| 111 |
| 112 git_cmd = ['git', 'cl', 'upload', '--send-mail', |
| 113 '--cc', ','.join(self.ALWAYS_CC)] |
| 114 tool.executive.run_and_throw_if_fail(git_cmd) |
82 # If there are changes to git, upload. | 115 # If there are changes to git, upload. |
OLD | NEW |