senorblanco@chromium.org | 782f3b4 | 2012-10-29 18:06:26 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | ''' |
| 4 | Copyright 2012 Google Inc. |
| 5 | |
| 6 | Use of this source code is governed by a BSD-style license that can be |
| 7 | found in the LICENSE file. |
| 8 | ''' |
| 9 | |
| 10 | ''' |
senorblanco@chromium.org | 123a0b5 | 2012-11-29 21:50:34 +0000 | [diff] [blame] | 11 | Rebaselines the given GM tests, on all bots and all configurations. |
senorblanco@chromium.org | 782f3b4 | 2012-10-29 18:06:26 +0000 | [diff] [blame] | 12 | ''' |
| 13 | |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 14 | # System-level imports |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 15 | import argparse |
epoger@google.com | fd04011 | 2013-08-20 16:21:55 +0000 | [diff] [blame] | 16 | import json |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 17 | import os |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame] | 18 | import re |
epoger@google.com | 27e1c00 | 2013-07-24 15:38:39 +0000 | [diff] [blame] | 19 | import subprocess |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 20 | import sys |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 21 | import urllib2 |
| 22 | |
| 23 | # Imports from within Skia |
| 24 | # |
epoger@google.com | dad5310 | 2013-06-12 14:25:30 +0000 | [diff] [blame] | 25 | # We need to add the 'gm' directory, so that we can import gm_json.py within |
| 26 | # that directory. That script allows us to parse the actual-results.json file |
| 27 | # written out by the GM tool. |
| 28 | # Make sure that the 'gm' dir is in the PYTHONPATH, but add it at the *end* |
| 29 | # so any dirs that are already in the PYTHONPATH will be preferred. |
| 30 | # |
| 31 | # This assumes that the 'gm' directory has been checked out as a sibling of |
| 32 | # the 'tools' directory containing this script, which will be the case if |
| 33 | # 'trunk' was checked out as a single unit. |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 34 | GM_DIRECTORY = os.path.realpath( |
| 35 | os.path.join(os.path.dirname(os.path.dirname(__file__)), 'gm')) |
| 36 | if GM_DIRECTORY not in sys.path: |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 37 | sys.path.append(GM_DIRECTORY) |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 38 | import gm_json |
| 39 | |
epoger@google.com | 44f165f | 2013-08-24 20:45:31 +0000 | [diff] [blame] | 40 | # TODO(epoger): In the long run, we want to build this list automatically, |
| 41 | # but for now we hard-code it until we can properly address |
| 42 | # https://code.google.com/p/skia/issues/detail?id=1544 |
| 43 | # ('live query of builder list makes rebaseline.py slow to start up') |
| 44 | TEST_BUILDERS = [ |
| 45 | 'Test-Android-GalaxyNexus-SGX540-Arm7-Debug', |
| 46 | 'Test-Android-GalaxyNexus-SGX540-Arm7-Release', |
| 47 | 'Test-Android-IntelRhb-SGX544-x86-Debug', |
| 48 | 'Test-Android-IntelRhb-SGX544-x86-Release', |
| 49 | 'Test-Android-Nexus10-MaliT604-Arm7-Debug', |
| 50 | 'Test-Android-Nexus10-MaliT604-Arm7-Release', |
| 51 | 'Test-Android-Nexus4-Adreno320-Arm7-Debug', |
| 52 | 'Test-Android-Nexus4-Adreno320-Arm7-Release', |
| 53 | 'Test-Android-Nexus7-Tegra3-Arm7-Debug', |
| 54 | 'Test-Android-Nexus7-Tegra3-Arm7-Release', |
| 55 | 'Test-Android-NexusS-SGX540-Arm7-Debug', |
| 56 | 'Test-Android-NexusS-SGX540-Arm7-Release', |
| 57 | 'Test-Android-Xoom-Tegra2-Arm7-Debug', |
| 58 | 'Test-Android-Xoom-Tegra2-Arm7-Release', |
| 59 | 'Test-ChromeOS-Alex-GMA3150-x86-Debug', |
| 60 | 'Test-ChromeOS-Alex-GMA3150-x86-Release', |
| 61 | 'Test-ChromeOS-Daisy-MaliT604-Arm7-Debug', |
| 62 | 'Test-ChromeOS-Daisy-MaliT604-Arm7-Release', |
| 63 | 'Test-ChromeOS-Link-HD4000-x86_64-Debug', |
| 64 | 'Test-ChromeOS-Link-HD4000-x86_64-Release', |
| 65 | 'Test-Mac10.6-MacMini4.1-GeForce320M-x86-Debug', |
| 66 | 'Test-Mac10.6-MacMini4.1-GeForce320M-x86-Release', |
| 67 | 'Test-Mac10.6-MacMini4.1-GeForce320M-x86_64-Debug', |
| 68 | 'Test-Mac10.6-MacMini4.1-GeForce320M-x86_64-Release', |
| 69 | 'Test-Mac10.7-MacMini4.1-GeForce320M-x86-Debug', |
| 70 | 'Test-Mac10.7-MacMini4.1-GeForce320M-x86-Release', |
| 71 | 'Test-Mac10.7-MacMini4.1-GeForce320M-x86_64-Debug', |
| 72 | 'Test-Mac10.7-MacMini4.1-GeForce320M-x86_64-Release', |
| 73 | 'Test-Mac10.8-MacMini4.1-GeForce320M-x86-Debug', |
| 74 | 'Test-Mac10.8-MacMini4.1-GeForce320M-x86-Release', |
| 75 | 'Test-Mac10.8-MacMini4.1-GeForce320M-x86_64-Debug', |
| 76 | 'Test-Mac10.8-MacMini4.1-GeForce320M-x86_64-Release', |
| 77 | 'Test-Ubuntu12-ShuttleA-ATI5770-x86-Debug', |
| 78 | 'Test-Ubuntu12-ShuttleA-ATI5770-x86-Release', |
| 79 | 'Test-Ubuntu12-ShuttleA-ATI5770-x86_64-Debug', |
| 80 | 'Test-Ubuntu12-ShuttleA-ATI5770-x86_64-Release', |
| 81 | 'Test-Ubuntu12-ShuttleA-HD2000-x86_64-Release-Valgrind', |
| 82 | 'Test-Ubuntu12-ShuttleA-NoGPU-x86_64-Debug', |
| 83 | 'Test-Ubuntu13-ShuttleA-HD2000-x86_64-Debug-ASAN', |
| 84 | 'Test-Win7-ShuttleA-HD2000-x86-Debug', |
| 85 | 'Test-Win7-ShuttleA-HD2000-x86-Debug-ANGLE', |
| 86 | 'Test-Win7-ShuttleA-HD2000-x86-Debug-DirectWrite', |
| 87 | 'Test-Win7-ShuttleA-HD2000-x86-Release', |
| 88 | 'Test-Win7-ShuttleA-HD2000-x86-Release-ANGLE', |
| 89 | 'Test-Win7-ShuttleA-HD2000-x86-Release-DirectWrite', |
| 90 | 'Test-Win7-ShuttleA-HD2000-x86_64-Debug', |
| 91 | 'Test-Win7-ShuttleA-HD2000-x86_64-Release', |
| 92 | ] |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 93 | |
borenet@google.com | b6e915d | 2013-09-16 18:13:13 +0000 | [diff] [blame] | 94 | # TODO: Get this from builder_name_schema in buildbot. |
| 95 | TRYBOT_SUFFIX = '-Trybot' |
| 96 | |
| 97 | |
epoger@google.com | 66ba9f9 | 2013-07-11 19:20:30 +0000 | [diff] [blame] | 98 | class _InternalException(Exception): |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 99 | pass |
epoger@google.com | db29a31 | 2013-06-04 14:58:47 +0000 | [diff] [blame] | 100 | |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame] | 101 | class ExceptionHandler(object): |
epoger@google.com | 93acfd2 | 2013-09-03 18:27:19 +0000 | [diff] [blame] | 102 | """ Object that handles exceptions, either raising them immediately or |
| 103 | collecting them to display later on.""" |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame] | 104 | |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 105 | # params: |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 106 | def __init__(self, keep_going_on_failure=False): |
epoger@google.com | 93acfd2 | 2013-09-03 18:27:19 +0000 | [diff] [blame] | 107 | """ |
| 108 | params: |
| 109 | keep_going_on_failure: if False, report failures and quit right away; |
| 110 | if True, collect failures until |
| 111 | ReportAllFailures() is called |
| 112 | """ |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 113 | self._keep_going_on_failure = keep_going_on_failure |
| 114 | self._failures_encountered = [] |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame] | 115 | |
epoger@google.com | 93acfd2 | 2013-09-03 18:27:19 +0000 | [diff] [blame] | 116 | def RaiseExceptionOrContinue(self): |
| 117 | """ We have encountered an exception; either collect the info and keep |
| 118 | going, or exit the program right away.""" |
| 119 | # Get traceback information about the most recently raised exception. |
| 120 | exc_info = sys.exc_info() |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame] | 121 | |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 122 | if self._keep_going_on_failure: |
epoger@google.com | 93acfd2 | 2013-09-03 18:27:19 +0000 | [diff] [blame] | 123 | print >> sys.stderr, ('WARNING: swallowing exception %s' % |
| 124 | repr(exc_info[1])) |
| 125 | self._failures_encountered.append(exc_info) |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 126 | else: |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 127 | print >> sys.stderr, ( |
epoger@google.com | 80f9cf1 | 2013-09-06 17:26:09 +0000 | [diff] [blame] | 128 | '\nHalting at first exception.\n' + |
| 129 | 'Please file a bug to epoger@google.com at ' + |
| 130 | 'https://code.google.com/p/skia/issues/entry, containing the ' + |
| 131 | 'command you ran and the following stack trace.\n\n' + |
| 132 | 'Afterwards, you can re-run with the --keep-going-on-failure ' + |
| 133 | 'option set.\n') |
epoger@google.com | 93acfd2 | 2013-09-03 18:27:19 +0000 | [diff] [blame] | 134 | raise exc_info[1], None, exc_info[2] |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame] | 135 | |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 136 | def ReportAllFailures(self): |
| 137 | if self._failures_encountered: |
| 138 | print >> sys.stderr, ('Encountered %d failures (see above).' % |
| 139 | len(self._failures_encountered)) |
epoger@google.com | 93acfd2 | 2013-09-03 18:27:19 +0000 | [diff] [blame] | 140 | sys.exit(1) |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame] | 141 | |
| 142 | |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 143 | # Object that rebaselines a JSON expectations file (not individual image files). |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 144 | class JsonRebaseliner(object): |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 145 | |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 146 | # params: |
| 147 | # expectations_root: root directory of all expectations JSON files |
| 148 | # expectations_input_filename: filename (under expectations_root) of JSON |
| 149 | # expectations file to read; typically |
| 150 | # "expected-results.json" |
| 151 | # expectations_output_filename: filename (under expectations_root) to |
| 152 | # which updated expectations should be |
| 153 | # written; typically the same as |
| 154 | # expectations_input_filename, to overwrite |
| 155 | # the old content |
| 156 | # actuals_base_url: base URL from which to read actual-result JSON files |
| 157 | # actuals_filename: filename (under actuals_base_url) from which to read a |
| 158 | # summary of results; typically "actual-results.json" |
| 159 | # exception_handler: reference to rebaseline.ExceptionHandler object |
| 160 | # tests: list of tests to rebaseline, or None if we should rebaseline |
| 161 | # whatever files the JSON results summary file tells us to |
| 162 | # configs: which configs to run for each test, or None if we should |
| 163 | # rebaseline whatever configs the JSON results summary file tells |
| 164 | # us to |
| 165 | # add_new: if True, add expectations for tests which don't have any yet |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 166 | # bugs: optional list of bug numbers which pertain to these expectations |
| 167 | # notes: free-form text notes to add to all updated expectations |
| 168 | # mark_unreviewed: if True, mark these expectations as NOT having been |
| 169 | # reviewed by a human; otherwise, leave that field blank. |
| 170 | # Currently, there is no way to make this script mark |
| 171 | # expectations as reviewed-by-human=True. |
| 172 | # TODO(epoger): Add that capability to a review tool. |
senorblanco@chromium.org | bfc0d6b | 2013-09-18 19:14:43 +0000 | [diff] [blame] | 173 | # mark_ignore_failure: if True, mark failures of a given test as being |
| 174 | # ignored. |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 175 | def __init__(self, expectations_root, expectations_input_filename, |
| 176 | expectations_output_filename, actuals_base_url, |
| 177 | actuals_filename, exception_handler, |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 178 | tests=None, configs=None, add_new=False, bugs=None, notes=None, |
senorblanco@chromium.org | bfc0d6b | 2013-09-18 19:14:43 +0000 | [diff] [blame] | 179 | mark_unreviewed=None, mark_ignore_failure=False, |
| 180 | from_trybot=False): |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 181 | self._expectations_root = expectations_root |
| 182 | self._expectations_input_filename = expectations_input_filename |
| 183 | self._expectations_output_filename = expectations_output_filename |
| 184 | self._tests = tests |
| 185 | self._configs = configs |
| 186 | self._actuals_base_url = actuals_base_url |
| 187 | self._actuals_filename = actuals_filename |
| 188 | self._exception_handler = exception_handler |
| 189 | self._add_new = add_new |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 190 | self._bugs = bugs |
| 191 | self._notes = notes |
| 192 | self._mark_unreviewed = mark_unreviewed |
senorblanco@chromium.org | bfc0d6b | 2013-09-18 19:14:43 +0000 | [diff] [blame] | 193 | self._mark_ignore_failure = mark_ignore_failure; |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 194 | self._image_filename_re = re.compile(gm_json.IMAGE_FILENAME_PATTERN) |
| 195 | self._using_svn = os.path.isdir(os.path.join(expectations_root, '.svn')) |
borenet@google.com | b6e915d | 2013-09-16 18:13:13 +0000 | [diff] [blame] | 196 | self._from_trybot = from_trybot |
epoger@google.com | 27e1c00 | 2013-07-24 15:38:39 +0000 | [diff] [blame] | 197 | |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 198 | # Executes subprocess.call(cmd). |
| 199 | # Raises an Exception if the command fails. |
| 200 | def _Call(self, cmd): |
| 201 | if subprocess.call(cmd) != 0: |
| 202 | raise _InternalException('error running command: ' + ' '.join(cmd)) |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 203 | |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 204 | # Returns the full contents of filepath, as a single string. |
| 205 | # If filepath looks like a URL, try to read it that way instead of as |
| 206 | # a path on local storage. |
| 207 | # |
| 208 | # Raises _InternalException if there is a problem. |
| 209 | def _GetFileContents(self, filepath): |
| 210 | if filepath.startswith('http:') or filepath.startswith('https:'): |
| 211 | try: |
| 212 | return urllib2.urlopen(filepath).read() |
| 213 | except urllib2.HTTPError as e: |
| 214 | raise _InternalException('unable to read URL %s: %s' % ( |
| 215 | filepath, e)) |
| 216 | else: |
| 217 | return open(filepath, 'r').read() |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 218 | |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 219 | # Returns a dictionary of actual results from actual-results.json file. |
| 220 | # |
| 221 | # The dictionary returned has this format: |
| 222 | # { |
| 223 | # u'imageblur_565.png': [u'bitmap-64bitMD5', 3359963596899141322], |
| 224 | # u'imageblur_8888.png': [u'bitmap-64bitMD5', 4217923806027861152], |
| 225 | # u'shadertext3_8888.png': [u'bitmap-64bitMD5', 3713708307125704716] |
| 226 | # } |
| 227 | # |
| 228 | # If the JSON actual result summary file cannot be loaded, logs a warning |
| 229 | # message and returns None. |
| 230 | # If the JSON actual result summary file can be loaded, but we have |
| 231 | # trouble parsing it, raises an Exception. |
| 232 | # |
| 233 | # params: |
| 234 | # json_url: URL pointing to a JSON actual result summary file |
| 235 | # sections: a list of section names to include in the results, e.g. |
| 236 | # [gm_json.JSONKEY_ACTUALRESULTS_FAILED, |
| 237 | # gm_json.JSONKEY_ACTUALRESULTS_NOCOMPARISON] ; |
| 238 | # if None, then include ALL sections. |
| 239 | def _GetActualResults(self, json_url, sections=None): |
| 240 | try: |
| 241 | json_contents = self._GetFileContents(json_url) |
| 242 | except _InternalException: |
| 243 | print >> sys.stderr, ( |
| 244 | 'could not read json_url %s ; skipping this platform.' % |
| 245 | json_url) |
| 246 | return None |
| 247 | json_dict = gm_json.LoadFromString(json_contents) |
| 248 | results_to_return = {} |
| 249 | actual_results = json_dict[gm_json.JSONKEY_ACTUALRESULTS] |
| 250 | if not sections: |
| 251 | sections = actual_results.keys() |
| 252 | for section in sections: |
| 253 | section_results = actual_results[section] |
| 254 | if section_results: |
| 255 | results_to_return.update(section_results) |
| 256 | return results_to_return |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame] | 257 | |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 258 | # Rebaseline all tests/types we specified in the constructor, |
epoger@google.com | fd04011 | 2013-08-20 16:21:55 +0000 | [diff] [blame] | 259 | # within this builder's subdirectory in expectations/gm . |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 260 | # |
| 261 | # params: |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 262 | # builder : e.g. 'Test-Win7-ShuttleA-HD2000-x86-Release' |
epoger@google.com | fd04011 | 2013-08-20 16:21:55 +0000 | [diff] [blame] | 263 | def RebaselineSubdir(self, builder): |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 264 | # Read in the actual result summary, and extract all the tests whose |
| 265 | # results we need to update. |
borenet@google.com | b6e915d | 2013-09-16 18:13:13 +0000 | [diff] [blame] | 266 | results_builder = str(builder) |
| 267 | if self._from_trybot: |
| 268 | results_builder = results_builder + TRYBOT_SUFFIX |
| 269 | actuals_url = '/'.join([self._actuals_base_url, results_builder, |
| 270 | self._actuals_filename]) |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 271 | # Only update results for tests that are currently failing. |
| 272 | # We don't want to rewrite results for tests that are already succeeding, |
| 273 | # because we don't want to add annotation fields (such as |
| 274 | # JSONKEY_EXPECTEDRESULTS_BUGS) except for tests whose expectations we |
| 275 | # are actually modifying. |
epoger@google.com | 7f5f6e6 | 2013-09-05 17:19:37 +0000 | [diff] [blame] | 276 | sections = [gm_json.JSONKEY_ACTUALRESULTS_FAILED] |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 277 | if self._add_new: |
| 278 | sections.append(gm_json.JSONKEY_ACTUALRESULTS_NOCOMPARISON) |
| 279 | results_to_update = self._GetActualResults(json_url=actuals_url, |
| 280 | sections=sections) |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame] | 281 | |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 282 | # Read in current expectations. |
| 283 | expectations_input_filepath = os.path.join( |
epoger@google.com | fd04011 | 2013-08-20 16:21:55 +0000 | [diff] [blame] | 284 | self._expectations_root, builder, self._expectations_input_filename) |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 285 | expectations_dict = gm_json.LoadFromFile(expectations_input_filepath) |
epoger@google.com | 93acfd2 | 2013-09-03 18:27:19 +0000 | [diff] [blame] | 286 | expected_results = expectations_dict.get(gm_json.JSONKEY_EXPECTEDRESULTS) |
| 287 | if not expected_results: |
| 288 | expected_results = {} |
| 289 | expectations_dict[gm_json.JSONKEY_EXPECTEDRESULTS] = expected_results |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 290 | |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 291 | # Update the expectations in memory, skipping any tests/configs that |
| 292 | # the caller asked to exclude. |
| 293 | skipped_images = [] |
| 294 | if results_to_update: |
| 295 | for (image_name, image_results) in results_to_update.iteritems(): |
| 296 | (test, config) = self._image_filename_re.match(image_name).groups() |
| 297 | if self._tests: |
| 298 | if test not in self._tests: |
| 299 | skipped_images.append(image_name) |
| 300 | continue |
| 301 | if self._configs: |
| 302 | if config not in self._configs: |
| 303 | skipped_images.append(image_name) |
| 304 | continue |
| 305 | if not expected_results.get(image_name): |
| 306 | expected_results[image_name] = {} |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 307 | expected_results[image_name]\ |
| 308 | [gm_json.JSONKEY_EXPECTEDRESULTS_ALLOWEDDIGESTS]\ |
| 309 | = [image_results] |
| 310 | if self._mark_unreviewed: |
| 311 | expected_results[image_name]\ |
| 312 | [gm_json.JSONKEY_EXPECTEDRESULTS_REVIEWED]\ |
| 313 | = False |
senorblanco@chromium.org | bfc0d6b | 2013-09-18 19:14:43 +0000 | [diff] [blame] | 314 | if self._mark_ignore_failure: |
| 315 | expected_results[image_name]\ |
| 316 | [gm_json.JSONKEY_EXPECTEDRESULTS_IGNOREFAILURE]\ |
| 317 | = True |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 318 | if self._bugs: |
| 319 | expected_results[image_name]\ |
| 320 | [gm_json.JSONKEY_EXPECTEDRESULTS_BUGS]\ |
| 321 | = self._bugs |
| 322 | if self._notes: |
| 323 | expected_results[image_name]\ |
| 324 | [gm_json.JSONKEY_EXPECTEDRESULTS_NOTES]\ |
| 325 | = self._notes |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 326 | |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 327 | # Write out updated expectations. |
| 328 | expectations_output_filepath = os.path.join( |
epoger@google.com | fd04011 | 2013-08-20 16:21:55 +0000 | [diff] [blame] | 329 | self._expectations_root, builder, self._expectations_output_filename) |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 330 | gm_json.WriteToFile(expectations_dict, expectations_output_filepath) |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 331 | |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 332 | # Mark the JSON file as plaintext, so text-style diffs can be applied. |
| 333 | # Fixes https://code.google.com/p/skia/issues/detail?id=1442 |
| 334 | if self._using_svn: |
| 335 | self._Call(['svn', 'propset', '--quiet', 'svn:mime-type', |
| 336 | 'text/x-json', expectations_output_filepath]) |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 337 | |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 338 | # main... |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 339 | |
epoger@google.com | 6d28e8d | 2013-09-18 14:58:47 +0000 | [diff] [blame] | 340 | parser = argparse.ArgumentParser( |
| 341 | formatter_class=argparse.RawDescriptionHelpFormatter, |
| 342 | epilog='Here is the full set of builders we know about:' + |
| 343 | '\n '.join([''] + sorted(TEST_BUILDERS))) |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 344 | parser.add_argument('--actuals-base-url', |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 345 | help=('base URL from which to read files containing JSON ' |
| 346 | 'summaries of actual GM results; defaults to ' |
| 347 | '%(default)s'), |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 348 | default='http://skia-autogen.googlecode.com/svn/gm-actual') |
| 349 | parser.add_argument('--actuals-filename', |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 350 | help=('filename (within builder-specific subdirectories ' |
| 351 | 'of ACTUALS_BASE_URL) to read a summary of results ' |
| 352 | 'from; defaults to %(default)s'), |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 353 | default='actual-results.json') |
epoger@google.com | dad5310 | 2013-06-12 14:25:30 +0000 | [diff] [blame] | 354 | parser.add_argument('--add-new', action='store_true', |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 355 | help=('in addition to the standard behavior of ' |
| 356 | 'updating expectations for failing tests, add ' |
| 357 | 'expectations for tests which don\'t have ' |
| 358 | 'expectations yet.')) |
| 359 | parser.add_argument('--bugs', metavar='BUG', type=int, nargs='+', |
| 360 | help=('Skia bug numbers (under ' |
| 361 | 'https://code.google.com/p/skia/issues/list ) which ' |
| 362 | 'pertain to this set of rebaselines.')) |
epoger@google.com | fd04011 | 2013-08-20 16:21:55 +0000 | [diff] [blame] | 363 | parser.add_argument('--builders', metavar='BUILDER', nargs='+', |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 364 | help=('which platforms to rebaseline; ' |
epoger@google.com | 6d28e8d | 2013-09-18 14:58:47 +0000 | [diff] [blame] | 365 | 'if unspecified, rebaseline all known platforms ' |
| 366 | '(see below for a list)')) |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 367 | # TODO(epoger): Add test that exercises --configs argument. |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 368 | parser.add_argument('--configs', metavar='CONFIG', nargs='+', |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 369 | help=('which configurations to rebaseline, e.g. ' |
| 370 | '"--configs 565 8888", as a filter over the full set ' |
| 371 | 'of results in ACTUALS_FILENAME; if unspecified, ' |
| 372 | 'rebaseline *all* configs that are available.')) |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 373 | parser.add_argument('--expectations-filename', |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 374 | help=('filename (under EXPECTATIONS_ROOT) to read ' |
| 375 | 'current expectations from, and to write new ' |
| 376 | 'expectations into (unless a separate ' |
| 377 | 'EXPECTATIONS_FILENAME_OUTPUT has been specified); ' |
| 378 | 'defaults to %(default)s'), |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 379 | default='expected-results.json') |
epoger@google.com | c60e745 | 2013-07-24 19:36:51 +0000 | [diff] [blame] | 380 | parser.add_argument('--expectations-filename-output', |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 381 | help=('filename (under EXPECTATIONS_ROOT) to write ' |
| 382 | 'updated expectations into; by default, overwrites ' |
| 383 | 'the input file (EXPECTATIONS_FILENAME)'), |
epoger@google.com | c60e745 | 2013-07-24 19:36:51 +0000 | [diff] [blame] | 384 | default='') |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 385 | parser.add_argument('--expectations-root', |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 386 | help=('root of expectations directory to update-- should ' |
| 387 | 'contain one or more builder subdirectories. ' |
| 388 | 'Defaults to %(default)s'), |
epoger@google.com | e94a7d2 | 2013-07-23 19:37:03 +0000 | [diff] [blame] | 389 | default=os.path.join('expectations', 'gm')) |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame] | 390 | parser.add_argument('--keep-going-on-failure', action='store_true', |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 391 | help=('instead of halting at the first error encountered, ' |
| 392 | 'keep going and rebaseline as many tests as ' |
| 393 | 'possible, and then report the full set of errors ' |
| 394 | 'at the end')) |
| 395 | parser.add_argument('--notes', |
| 396 | help=('free-form text notes to add to all updated ' |
| 397 | 'expectations')) |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 398 | # TODO(epoger): Add test that exercises --tests argument. |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 399 | parser.add_argument('--tests', metavar='TEST', nargs='+', |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 400 | help=('which tests to rebaseline, e.g. ' |
| 401 | '"--tests aaclip bigmatrix", as a filter over the ' |
| 402 | 'full set of results in ACTUALS_FILENAME; if ' |
| 403 | 'unspecified, rebaseline *all* tests that are ' |
| 404 | 'available.')) |
| 405 | parser.add_argument('--unreviewed', action='store_true', |
| 406 | help=('mark all expectations modified by this run as ' |
| 407 | '"%s": False' % |
| 408 | gm_json.JSONKEY_EXPECTEDRESULTS_REVIEWED)) |
senorblanco@chromium.org | bfc0d6b | 2013-09-18 19:14:43 +0000 | [diff] [blame] | 409 | parser.add_argument('--ignore-failure', action='store_true', |
| 410 | help=('mark all expectations modified by this run as ' |
| 411 | '"%s": True' % |
| 412 | gm_json.JSONKEY_ACTUALRESULTS_FAILUREIGNORED)) |
borenet@google.com | b6e915d | 2013-09-16 18:13:13 +0000 | [diff] [blame] | 413 | parser.add_argument('--from-trybot', action='store_true', |
| 414 | help=('pull the actual-results.json file from the ' |
| 415 | 'corresponding trybot, rather than the main builder')) |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 416 | args = parser.parse_args() |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame] | 417 | exception_handler = ExceptionHandler( |
| 418 | keep_going_on_failure=args.keep_going_on_failure) |
epoger@google.com | fd04011 | 2013-08-20 16:21:55 +0000 | [diff] [blame] | 419 | if args.builders: |
| 420 | builders = args.builders |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 421 | missing_json_is_fatal = True |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 422 | else: |
epoger@google.com | fd04011 | 2013-08-20 16:21:55 +0000 | [diff] [blame] | 423 | builders = sorted(TEST_BUILDERS) |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 424 | missing_json_is_fatal = False |
epoger@google.com | fd04011 | 2013-08-20 16:21:55 +0000 | [diff] [blame] | 425 | for builder in builders: |
| 426 | if not builder in TEST_BUILDERS: |
| 427 | raise Exception(('unrecognized builder "%s"; ' + |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 428 | 'should be one of %s') % ( |
epoger@google.com | fd04011 | 2013-08-20 16:21:55 +0000 | [diff] [blame] | 429 | builder, TEST_BUILDERS)) |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 430 | |
epoger@google.com | fd04011 | 2013-08-20 16:21:55 +0000 | [diff] [blame] | 431 | expectations_json_file = os.path.join(args.expectations_root, builder, |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 432 | args.expectations_filename) |
| 433 | if os.path.isfile(expectations_json_file): |
| 434 | rebaseliner = JsonRebaseliner( |
| 435 | expectations_root=args.expectations_root, |
| 436 | expectations_input_filename=args.expectations_filename, |
| 437 | expectations_output_filename=(args.expectations_filename_output or |
| 438 | args.expectations_filename), |
| 439 | tests=args.tests, configs=args.configs, |
| 440 | actuals_base_url=args.actuals_base_url, |
| 441 | actuals_filename=args.actuals_filename, |
| 442 | exception_handler=exception_handler, |
epoger@google.com | 06e626d | 2013-09-03 17:32:15 +0000 | [diff] [blame] | 443 | add_new=args.add_new, bugs=args.bugs, notes=args.notes, |
borenet@google.com | b6e915d | 2013-09-16 18:13:13 +0000 | [diff] [blame] | 444 | mark_unreviewed=args.unreviewed, |
senorblanco@chromium.org | bfc0d6b | 2013-09-18 19:14:43 +0000 | [diff] [blame] | 445 | mark_ignore_failure=args.ignore_failure, |
borenet@google.com | b6e915d | 2013-09-16 18:13:13 +0000 | [diff] [blame] | 446 | from_trybot=args.from_trybot) |
epoger@google.com | 3e7399f | 2013-07-10 17:23:47 +0000 | [diff] [blame] | 447 | try: |
epoger@google.com | fd04011 | 2013-08-20 16:21:55 +0000 | [diff] [blame] | 448 | rebaseliner.RebaselineSubdir(builder=builder) |
epoger@google.com | 93acfd2 | 2013-09-03 18:27:19 +0000 | [diff] [blame] | 449 | except: |
| 450 | exception_handler.RaiseExceptionOrContinue() |
epoger@google.com | 2a192a8 | 2013-08-02 20:54:46 +0000 | [diff] [blame] | 451 | else: |
epoger@google.com | 93acfd2 | 2013-09-03 18:27:19 +0000 | [diff] [blame] | 452 | try: |
| 453 | raise _InternalException('expectations_json_file %s not found' % |
| 454 | expectations_json_file) |
| 455 | except: |
| 456 | exception_handler.RaiseExceptionOrContinue() |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame] | 457 | |
| 458 | exception_handler.ReportAllFailures() |