Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: Tools/Scripts/webkitpy/tool/commands/flakytests.py

Issue 307183002: Teach webkit-patch update-flaky-tests how to upload a change (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Don't need MockTool Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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)
56 # This is sorta silly, but allows for unit testing:
57 self.expectations_factory = BotTestExpectationsFactory
46 58
47 def execute(self, options, args, tool): 59 def _collect_expectation_lines(self, port_names, factory):
48 port = tool.port_factory.get()
49 model = TestExpectationsModel() 60 model = TestExpectationsModel()
50 for port_name in tool.port_factory.all_port_names(): 61 for port_name in port_names:
51 expectations = BotTestExpectationsFactory().expectations_for_port(po rt_name) 62 expectations = factory.expectations_for_port(port_name)
52 for line in expectations.expectation_lines(only_ignore_very_flaky=Tr ue): 63 for line in expectations.expectation_lines(only_ignore_very_flaky=Tr ue):
53 model.add_expectation_line(line) 64 model.add_expectation_line(line)
54 # FIXME: We need an official API to get all the test names or all test l ines. 65 # 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() 66 return model._test_to_expectation_line.values()
56 lines.sort(key=lambda line: line.path)
57 # Skip any tests which are mentioned in the dashboard but not in our che ckout:
58 fs = tool.filesystem
59 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')
61 # Note: This includes all flaky tests from the dashboard, even ones ment ioned
62 # in existing TestExpectations. We could certainly load existing TestExp ecations
63 # and filter accordingly, or update existing TestExpectations instead of FlakyTests.
64 with open(flaky_tests_path, 'w') as flake_file:
65 flake_file.write(TestExpectations.list_to_string(lines))
66 67
67 if not options.upload: 68 def _commit_and_upload(self, tool, options):
68 return 0
69
70 files = tool.scm().changed_files() 69 files = tool.scm().changed_files()
71 flaky_tests_path = 'LayoutTests/FlakyTests' 70 flaky_tests_path = 'LayoutTests/FlakyTests'
72 if flaky_tests_path not in files: 71 if flaky_tests_path not in files:
73 print "%s is not changed, not uploading." % flaky_tests_path 72 print "%s is not changed, not uploading." % flaky_tests_path
74 return 0 73 return 0
75 74
76 commit_message = "Update FlakyTests" 75 if options.reviewers:
77 git_cmd = ['git', 'commit', '-m', commit_message, flaky_tests_path] 76 # FIXME: Could validate these as emails. sheriff_calendar has some c ode for that.
78 tool.executive.run_command(git_cmd) 77 reviewer_emails = options.reviewers.split(',')
78 else:
79 reviewer_emails = sheriff_calendar.current_gardener_emails()
80 if not reviewer_emails:
81 print "No gardener, and --reviewers not specified, not bothering ."
82 return 1
79 83
80 git_cmd = ['git', 'cl', 'upload', '--use-commit-queue', '--send-mail'] 84 commit_message = """Update FlakyTests to match current flakiness dashboa rd results
81 tool.executive.run_command(git_cmd) 85
82 # If there are changes to git, upload. 86 Automatically generated using:
87 webkit-patch update-flaky-tests
88
89 R=%s
90 """ % ','.join(reviewer_emails)
91
92 git_cmd = ['git', 'commit', '-m', commit_message,
93 tool.filesystem.join(tool.scm().checkout_root, flaky_tests_path)]
94 tool.executive.run_and_throw_if_fail(git_cmd)
95
96 # FIXME: There must be a cleaner way to avoid the editor!
97 # Silence the editor.
98 os.environ['EDITOR'] = 'true'
99
100 git_cmd = ['git', 'cl', 'upload', '--send-mail',
101 '--cc', ','.join(self.ALWAYS_CC)]
102 tool.executive.run_and_throw_if_fail(git_cmd)
103
104 def execute(self, options, args, tool):
105 port = tool.port_factory.get()
106 port_names = tool.port_factory.all_port_names()
107 factory = self.expectations_factory()
108 lines = self._collect_expectation_lines(port_names, factory)
109 lines.sort(key=lambda line: line.path)
110 # Skip any tests which are mentioned in the dashboard but not in our che ckout:
111 fs = tool.filesystem
112 lines = filter(lambda line: fs.exists(fs.join(port.layout_tests_dir(), l ine.path)), lines)
113
114 # Note: This includes all flaky tests from the dashboard, even ones ment ioned
115 # in existing TestExpectations. We could certainly load existing TestExp ecations
116 # and filter accordingly, or update existing TestExpectations instead of FlakyTests.
117 flaky_tests_path = fs.join(port.layout_tests_dir(), 'FlakyTests')
118 fs.write_text_file(flaky_tests_path, TestExpectations.list_to_string(lin es))
119 print "Updated %s" % flaky_tests_path
120
121 if options.upload:
122 return self._commit_and_upload(tool, options)
123
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698