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. |
epoger@google.com | 61822a2 | 2013-07-16 18:56:32 +0000 | [diff] [blame] | 12 | |
| 13 | TODO(epoger): Fix indentation in this file (2-space indents, not 4-space). |
senorblanco@chromium.org | 782f3b4 | 2012-10-29 18:06:26 +0000 | [diff] [blame] | 14 | ''' |
| 15 | |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 16 | # System-level imports |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 17 | import argparse |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 18 | import os |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame] | 19 | import re |
epoger@google.com | 27e1c00 | 2013-07-24 15:38:39 +0000 | [diff] [blame] | 20 | import subprocess |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 21 | import sys |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 22 | import urllib2 |
| 23 | |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 24 | # Imports from local directory |
| 25 | import rebaseline_imagefiles |
| 26 | |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 27 | # Imports from within Skia |
| 28 | # |
epoger@google.com | dad5310 | 2013-06-12 14:25:30 +0000 | [diff] [blame] | 29 | # We need to add the 'gm' directory, so that we can import gm_json.py within |
| 30 | # that directory. That script allows us to parse the actual-results.json file |
| 31 | # written out by the GM tool. |
| 32 | # Make sure that the 'gm' dir is in the PYTHONPATH, but add it at the *end* |
| 33 | # so any dirs that are already in the PYTHONPATH will be preferred. |
| 34 | # |
| 35 | # This assumes that the 'gm' directory has been checked out as a sibling of |
| 36 | # the 'tools' directory containing this script, which will be the case if |
| 37 | # 'trunk' was checked out as a single unit. |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 38 | GM_DIRECTORY = os.path.realpath( |
| 39 | os.path.join(os.path.dirname(os.path.dirname(__file__)), 'gm')) |
| 40 | if GM_DIRECTORY not in sys.path: |
| 41 | sys.path.append(GM_DIRECTORY) |
| 42 | import gm_json |
| 43 | |
epoger@google.com | e94a7d2 | 2013-07-23 19:37:03 +0000 | [diff] [blame] | 44 | # Mapping of expectations/gm subdir (under |
| 45 | # https://skia.googlecode.com/svn/trunk/expectations/gm/ ) |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 46 | # to builder name (see list at http://108.170.217.252:10117/builders ) |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 47 | SUBDIR_MAPPING = { |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 48 | 'base-shuttle-win7-intel-float': |
| 49 | 'Test-Win7-ShuttleA-HD2000-x86-Release', |
| 50 | 'base-shuttle-win7-intel-angle': |
| 51 | 'Test-Win7-ShuttleA-HD2000-x86-Release-ANGLE', |
| 52 | 'base-shuttle-win7-intel-directwrite': |
| 53 | 'Test-Win7-ShuttleA-HD2000-x86-Release-DirectWrite', |
| 54 | 'base-shuttle_ubuntu12_ati5770': |
| 55 | 'Test-Ubuntu12-ShuttleA-ATI5770-x86_64-Release', |
| 56 | 'base-macmini': |
| 57 | 'Test-Mac10.6-MacMini4.1-GeForce320M-x86-Release', |
| 58 | 'base-macmini-lion-float': |
| 59 | 'Test-Mac10.7-MacMini4.1-GeForce320M-x86-Release', |
| 60 | 'base-android-galaxy-nexus': |
| 61 | 'Test-Android-GalaxyNexus-SGX540-Arm7-Debug', |
| 62 | 'base-android-nexus-7': |
| 63 | 'Test-Android-Nexus7-Tegra3-Arm7-Release', |
| 64 | 'base-android-nexus-s': |
| 65 | 'Test-Android-NexusS-SGX540-Arm7-Release', |
| 66 | 'base-android-xoom': |
| 67 | 'Test-Android-Xoom-Tegra2-Arm7-Release', |
| 68 | 'base-android-nexus-10': |
| 69 | 'Test-Android-Nexus10-MaliT604-Arm7-Release', |
robertphillips@google.com | 63e9627 | 2013-07-02 12:54:37 +0000 | [diff] [blame] | 70 | 'base-android-nexus-4': |
| 71 | 'Test-Android-Nexus4-Adreno320-Arm7-Release', |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 72 | } |
| 73 | |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 74 | |
epoger@google.com | 66ba9f9 | 2013-07-11 19:20:30 +0000 | [diff] [blame] | 75 | class _InternalException(Exception): |
epoger@google.com | db29a31 | 2013-06-04 14:58:47 +0000 | [diff] [blame] | 76 | pass |
| 77 | |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame] | 78 | # Object that handles exceptions, either raising them immediately or collecting |
| 79 | # them to display later on. |
| 80 | class ExceptionHandler(object): |
| 81 | |
| 82 | # params: |
| 83 | # keep_going_on_failure: if False, report failures and quit right away; |
| 84 | # if True, collect failures until |
| 85 | # ReportAllFailures() is called |
| 86 | def __init__(self, keep_going_on_failure=False): |
| 87 | self._keep_going_on_failure = keep_going_on_failure |
| 88 | self._failures_encountered = [] |
| 89 | self._exiting = False |
| 90 | |
| 91 | # Exit the program with the given status value. |
| 92 | def _Exit(self, status=1): |
| 93 | self._exiting = True |
| 94 | sys.exit(status) |
| 95 | |
| 96 | # We have encountered an exception; either collect the info and keep going, |
| 97 | # or exit the program right away. |
| 98 | def RaiseExceptionOrContinue(self, e): |
| 99 | # If we are already quitting the program, propagate any exceptions |
| 100 | # so that the proper exit status will be communicated to the shell. |
| 101 | if self._exiting: |
| 102 | raise e |
| 103 | |
| 104 | if self._keep_going_on_failure: |
| 105 | print >> sys.stderr, 'WARNING: swallowing exception %s' % e |
| 106 | self._failures_encountered.append(e) |
| 107 | else: |
| 108 | print >> sys.stderr, e |
| 109 | print >> sys.stderr, ( |
| 110 | 'Halting at first exception; to keep going, re-run ' + |
| 111 | 'with the --keep-going-on-failure option set.') |
| 112 | self._Exit() |
| 113 | |
| 114 | def ReportAllFailures(self): |
| 115 | if self._failures_encountered: |
| 116 | print >> sys.stderr, ('Encountered %d failures (see above).' % |
| 117 | len(self._failures_encountered)) |
| 118 | self._Exit() |
| 119 | |
| 120 | |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 121 | # Object that rebaselines a JSON expectations file (not individual image files). |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 122 | class JsonRebaseliner(object): |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 123 | |
| 124 | # params: |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 125 | # expectations_root: root directory of all expectations JSON files |
epoger@google.com | c60e745 | 2013-07-24 19:36:51 +0000 | [diff] [blame^] | 126 | # expectations_input_filename: filename (under expectations_root) of JSON |
| 127 | # expectations file to read; typically |
| 128 | # "expected-results.json" |
| 129 | # expectations_output_filename: filename (under expectations_root) to |
| 130 | # which updated expectations should be |
| 131 | # written; typically the same as |
| 132 | # expectations_input_filename, to overwrite |
| 133 | # the old content |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 134 | # actuals_base_url: base URL from which to read actual-result JSON files |
| 135 | # actuals_filename: filename (under actuals_base_url) from which to read a |
| 136 | # summary of results; typically "actual-results.json" |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame] | 137 | # exception_handler: reference to rebaseline.ExceptionHandler object |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 138 | # tests: list of tests to rebaseline, or None if we should rebaseline |
| 139 | # whatever files the JSON results summary file tells us to |
epoger@google.com | 9de25e3 | 2013-07-10 15:27:18 +0000 | [diff] [blame] | 140 | # configs: which configs to run for each test, or None if we should |
| 141 | # rebaseline whatever configs the JSON results summary file tells |
| 142 | # us to |
epoger@google.com | dad5310 | 2013-06-12 14:25:30 +0000 | [diff] [blame] | 143 | # add_new: if True, add expectations for tests which don't have any yet |
epoger@google.com | c60e745 | 2013-07-24 19:36:51 +0000 | [diff] [blame^] | 144 | def __init__(self, expectations_root, expectations_input_filename, |
| 145 | expectations_output_filename, actuals_base_url, |
| 146 | actuals_filename, exception_handler, |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 147 | tests=None, configs=None, add_new=False): |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 148 | self._expectations_root = expectations_root |
epoger@google.com | c60e745 | 2013-07-24 19:36:51 +0000 | [diff] [blame^] | 149 | self._expectations_input_filename = expectations_input_filename |
| 150 | self._expectations_output_filename = expectations_output_filename |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 151 | self._tests = tests |
| 152 | self._configs = configs |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 153 | self._actuals_base_url = actuals_base_url |
| 154 | self._actuals_filename = actuals_filename |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame] | 155 | self._exception_handler = exception_handler |
epoger@google.com | dad5310 | 2013-06-12 14:25:30 +0000 | [diff] [blame] | 156 | self._add_new = add_new |
epoger@google.com | 61822a2 | 2013-07-16 18:56:32 +0000 | [diff] [blame] | 157 | self._image_filename_re = re.compile(gm_json.IMAGE_FILENAME_PATTERN) |
epoger@google.com | 27e1c00 | 2013-07-24 15:38:39 +0000 | [diff] [blame] | 158 | self._using_svn = os.path.isdir(os.path.join(expectations_root, '.svn')) |
| 159 | |
| 160 | # Executes subprocess.call(cmd). |
| 161 | # Raises an Exception if the command fails. |
| 162 | def _Call(self, cmd): |
| 163 | if subprocess.call(cmd) != 0: |
| 164 | raise _InternalException('error running command: ' + ' '.join(cmd)) |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 165 | |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 166 | # Returns the full contents of filepath, as a single string. |
| 167 | # If filepath looks like a URL, try to read it that way instead of as |
| 168 | # a path on local storage. |
epoger@google.com | 66ba9f9 | 2013-07-11 19:20:30 +0000 | [diff] [blame] | 169 | # |
| 170 | # Raises _InternalException if there is a problem. |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 171 | def _GetFileContents(self, filepath): |
| 172 | if filepath.startswith('http:') or filepath.startswith('https:'): |
epoger@google.com | 66ba9f9 | 2013-07-11 19:20:30 +0000 | [diff] [blame] | 173 | try: |
| 174 | return urllib2.urlopen(filepath).read() |
| 175 | except urllib2.HTTPError as e: |
| 176 | raise _InternalException('unable to read URL %s: %s' % ( |
| 177 | filepath, e)) |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 178 | else: |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 179 | return open(filepath, 'r').read() |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 180 | |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame] | 181 | # Returns a dictionary of actual results from actual-results.json file. |
| 182 | # |
| 183 | # The dictionary returned has this format: |
| 184 | # { |
| 185 | # u'imageblur_565.png': [u'bitmap-64bitMD5', 3359963596899141322], |
| 186 | # u'imageblur_8888.png': [u'bitmap-64bitMD5', 4217923806027861152], |
| 187 | # u'shadertext3_8888.png': [u'bitmap-64bitMD5', 3713708307125704716] |
| 188 | # } |
| 189 | # |
epoger@google.com | 66ba9f9 | 2013-07-11 19:20:30 +0000 | [diff] [blame] | 190 | # If the JSON actual result summary file cannot be loaded, logs a warning |
| 191 | # message and returns None. |
| 192 | # If the JSON actual result summary file can be loaded, but we have |
| 193 | # trouble parsing it, raises an Exception. |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame] | 194 | # |
| 195 | # params: |
| 196 | # json_url: URL pointing to a JSON actual result summary file |
| 197 | # sections: a list of section names to include in the results, e.g. |
| 198 | # [gm_json.JSONKEY_ACTUALRESULTS_FAILED, |
| 199 | # gm_json.JSONKEY_ACTUALRESULTS_NOCOMPARISON] ; |
| 200 | # if None, then include ALL sections. |
| 201 | def _GetActualResults(self, json_url, sections=None): |
epoger@google.com | 66ba9f9 | 2013-07-11 19:20:30 +0000 | [diff] [blame] | 202 | try: |
| 203 | json_contents = self._GetFileContents(json_url) |
| 204 | except _InternalException: |
| 205 | print >> sys.stderr, ( |
| 206 | 'could not read json_url %s ; skipping this platform.' % |
| 207 | json_url) |
| 208 | return None |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame] | 209 | json_dict = gm_json.LoadFromString(json_contents) |
| 210 | results_to_return = {} |
| 211 | actual_results = json_dict[gm_json.JSONKEY_ACTUALRESULTS] |
| 212 | if not sections: |
| 213 | sections = actual_results.keys() |
| 214 | for section in sections: |
| 215 | section_results = actual_results[section] |
| 216 | if section_results: |
| 217 | results_to_return.update(section_results) |
| 218 | return results_to_return |
| 219 | |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 220 | # Rebaseline all tests/types we specified in the constructor, |
epoger@google.com | e94a7d2 | 2013-07-23 19:37:03 +0000 | [diff] [blame] | 221 | # within this expectations/gm subdir. |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 222 | # |
| 223 | # params: |
| 224 | # subdir : e.g. 'base-shuttle-win7-intel-float' |
| 225 | # builder : e.g. 'Test-Win7-ShuttleA-HD2000-x86-Release' |
| 226 | def RebaselineSubdir(self, subdir, builder): |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 227 | # Read in the actual result summary, and extract all the tests whose |
| 228 | # results we need to update. |
| 229 | actuals_url = '/'.join([self._actuals_base_url, |
| 230 | subdir, builder, subdir, |
| 231 | self._actuals_filename]) |
epoger@google.com | b248dd5 | 2013-07-17 00:09:10 +0000 | [diff] [blame] | 232 | # In most cases, we won't need to re-record results that are already |
| 233 | # succeeding, but including the SUCCEEDED results will allow us to |
| 234 | # re-record expectations if they somehow get out of sync. |
| 235 | sections = [gm_json.JSONKEY_ACTUALRESULTS_FAILED, |
| 236 | gm_json.JSONKEY_ACTUALRESULTS_SUCCEEDED] |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 237 | if self._add_new: |
| 238 | sections.append(gm_json.JSONKEY_ACTUALRESULTS_NOCOMPARISON) |
| 239 | results_to_update = self._GetActualResults(json_url=actuals_url, |
| 240 | sections=sections) |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame] | 241 | |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 242 | # Read in current expectations. |
epoger@google.com | c60e745 | 2013-07-24 19:36:51 +0000 | [diff] [blame^] | 243 | expectations_input_filepath = os.path.join( |
| 244 | self._expectations_root, subdir, self._expectations_input_filename) |
| 245 | expectations_dict = gm_json.LoadFromFile(expectations_input_filepath) |
epoger@google.com | 4b38301 | 2013-07-16 21:10:54 +0000 | [diff] [blame] | 246 | expected_results = expectations_dict[gm_json.JSONKEY_EXPECTEDRESULTS] |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 247 | |
| 248 | # Update the expectations in memory, skipping any tests/configs that |
| 249 | # the caller asked to exclude. |
| 250 | skipped_images = [] |
| 251 | if results_to_update: |
| 252 | for (image_name, image_results) in results_to_update.iteritems(): |
epoger@google.com | 61822a2 | 2013-07-16 18:56:32 +0000 | [diff] [blame] | 253 | (test, config) = \ |
| 254 | self._image_filename_re.match(image_name).groups() |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 255 | if self._tests: |
| 256 | if test not in self._tests: |
| 257 | skipped_images.append(image_name) |
| 258 | continue |
| 259 | if self._configs: |
| 260 | if config not in self._configs: |
| 261 | skipped_images.append(image_name) |
| 262 | continue |
epoger@google.com | 4b38301 | 2013-07-16 21:10:54 +0000 | [diff] [blame] | 263 | if not expected_results.get(image_name): |
| 264 | expected_results[image_name] = {} |
| 265 | expected_results[image_name] \ |
epoger@google.com | 61822a2 | 2013-07-16 18:56:32 +0000 | [diff] [blame] | 266 | [gm_json.JSONKEY_EXPECTEDRESULTS_ALLOWEDDIGESTS] = \ |
| 267 | [image_results] |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 268 | |
| 269 | # Write out updated expectations. |
epoger@google.com | c60e745 | 2013-07-24 19:36:51 +0000 | [diff] [blame^] | 270 | expectations_output_filepath = os.path.join( |
| 271 | self._expectations_root, subdir, self._expectations_output_filename) |
| 272 | gm_json.WriteToFile(expectations_dict, expectations_output_filepath) |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 273 | |
epoger@google.com | 27e1c00 | 2013-07-24 15:38:39 +0000 | [diff] [blame] | 274 | # Mark the JSON file as plaintext, so text-style diffs can be applied. |
| 275 | # Fixes https://code.google.com/p/skia/issues/detail?id=1442 |
| 276 | if self._using_svn: |
| 277 | self._Call(['svn', 'propset', '--quiet', 'svn:mime-type', |
epoger@google.com | c60e745 | 2013-07-24 19:36:51 +0000 | [diff] [blame^] | 278 | 'text/x-json', expectations_output_filepath]) |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 279 | |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 280 | # main... |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 281 | |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 282 | parser = argparse.ArgumentParser() |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 283 | parser.add_argument('--actuals-base-url', |
| 284 | help='base URL from which to read files containing JSON ' + |
| 285 | 'summaries of actual GM results; defaults to %(default)s', |
| 286 | default='http://skia-autogen.googlecode.com/svn/gm-actual') |
| 287 | parser.add_argument('--actuals-filename', |
| 288 | help='filename (within platform-specific subdirectories ' + |
| 289 | 'of ACTUALS_BASE_URL) to read a summary of results from; ' + |
| 290 | 'defaults to %(default)s', |
| 291 | default='actual-results.json') |
| 292 | # TODO(epoger): Add test that exercises --add-new argument. |
epoger@google.com | dad5310 | 2013-06-12 14:25:30 +0000 | [diff] [blame] | 293 | parser.add_argument('--add-new', action='store_true', |
| 294 | help='in addition to the standard behavior of ' + |
| 295 | 'updating expectations for failing tests, add ' + |
| 296 | 'expectations for tests which don\'t have expectations ' + |
| 297 | 'yet.') |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 298 | # TODO(epoger): Add test that exercises --configs argument. |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 299 | parser.add_argument('--configs', metavar='CONFIG', nargs='+', |
| 300 | help='which configurations to rebaseline, e.g. ' + |
epoger@google.com | 9de25e3 | 2013-07-10 15:27:18 +0000 | [diff] [blame] | 301 | '"--configs 565 8888", as a filter over the full set of ' + |
| 302 | 'results in ACTUALS_FILENAME; if unspecified, rebaseline ' + |
| 303 | '*all* configs that are available.') |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 304 | # TODO(epoger): The --dry-run argument will no longer be needed once we |
| 305 | # are only rebaselining JSON files. |
epoger@google.com | 82f3178 | 2013-06-11 15:45:46 +0000 | [diff] [blame] | 306 | parser.add_argument('--dry-run', action='store_true', |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 307 | help='instead of actually downloading files or adding ' + |
| 308 | 'files to checkout, display a list of operations that ' + |
| 309 | 'we would normally perform') |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 310 | parser.add_argument('--expectations-filename', |
| 311 | help='filename (under EXPECTATIONS_ROOT) to read ' + |
| 312 | 'current expectations from, and to write new ' + |
epoger@google.com | c60e745 | 2013-07-24 19:36:51 +0000 | [diff] [blame^] | 313 | 'expectations into (unless a separate ' + |
| 314 | 'EXPECTATIONS_FILENAME_OUTPUT has been specified); ' + |
| 315 | 'defaults to %(default)s', |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 316 | default='expected-results.json') |
epoger@google.com | c60e745 | 2013-07-24 19:36:51 +0000 | [diff] [blame^] | 317 | parser.add_argument('--expectations-filename-output', |
| 318 | help='filename (under EXPECTATIONS_ROOT) to write ' + |
| 319 | 'updated expectations into; by default, overwrites the ' + |
| 320 | 'input file (EXPECTATIONS_FILENAME)', |
| 321 | default='') |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 322 | parser.add_argument('--expectations-root', |
| 323 | help='root of expectations directory to update-- should ' + |
| 324 | 'contain one or more base-* subdirectories. Defaults to ' + |
| 325 | '%(default)s', |
epoger@google.com | e94a7d2 | 2013-07-23 19:37:03 +0000 | [diff] [blame] | 326 | default=os.path.join('expectations', 'gm')) |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame] | 327 | parser.add_argument('--keep-going-on-failure', action='store_true', |
| 328 | help='instead of halting at the first error encountered, ' + |
| 329 | 'keep going and rebaseline as many tests as possible, ' + |
| 330 | 'and then report the full set of errors at the end') |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 331 | parser.add_argument('--subdirs', metavar='SUBDIR', nargs='+', |
| 332 | help='which platform subdirectories to rebaseline; ' + |
| 333 | 'if unspecified, rebaseline all subdirs, same as ' + |
| 334 | '"--subdirs %s"' % ' '.join(sorted(SUBDIR_MAPPING.keys()))) |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 335 | # TODO(epoger): Add test that exercises --tests argument. |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 336 | parser.add_argument('--tests', metavar='TEST', nargs='+', |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 337 | help='which tests to rebaseline, e.g. ' + |
epoger@google.com | 9de25e3 | 2013-07-10 15:27:18 +0000 | [diff] [blame] | 338 | '"--tests aaclip bigmatrix", as a filter over the full ' + |
| 339 | 'set of results in ACTUALS_FILENAME; if unspecified, ' + |
| 340 | 'rebaseline *all* tests that are available.') |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 341 | args = parser.parse_args() |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame] | 342 | exception_handler = ExceptionHandler( |
| 343 | keep_going_on_failure=args.keep_going_on_failure) |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 344 | if args.subdirs: |
| 345 | subdirs = args.subdirs |
| 346 | missing_json_is_fatal = True |
| 347 | else: |
| 348 | subdirs = sorted(SUBDIR_MAPPING.keys()) |
| 349 | missing_json_is_fatal = False |
| 350 | for subdir in subdirs: |
| 351 | if not subdir in SUBDIR_MAPPING.keys(): |
| 352 | raise Exception(('unrecognized platform subdir "%s"; ' + |
| 353 | 'should be one of %s') % ( |
| 354 | subdir, SUBDIR_MAPPING.keys())) |
| 355 | builder = SUBDIR_MAPPING[subdir] |
| 356 | |
| 357 | # We instantiate different Rebaseliner objects depending |
| 358 | # on whether we are rebaselining an expected-results.json file, or |
epoger@google.com | e94a7d2 | 2013-07-23 19:37:03 +0000 | [diff] [blame] | 359 | # individual image files. Different expectations/gm subdirectories may move |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 360 | # from individual image files to JSON-format expectations at different |
| 361 | # times, so we need to make this determination per subdirectory. |
| 362 | # |
| 363 | # See https://goto.google.com/ChecksumTransitionDetail |
| 364 | expectations_json_file = os.path.join(args.expectations_root, subdir, |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 365 | args.expectations_filename) |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 366 | if os.path.isfile(expectations_json_file): |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 367 | rebaseliner = JsonRebaseliner( |
| 368 | expectations_root=args.expectations_root, |
epoger@google.com | c60e745 | 2013-07-24 19:36:51 +0000 | [diff] [blame^] | 369 | expectations_input_filename=args.expectations_filename, |
| 370 | expectations_output_filename=(args.expectations_filename_output or |
| 371 | args.expectations_filename), |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 372 | tests=args.tests, configs=args.configs, |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 373 | actuals_base_url=args.actuals_base_url, |
| 374 | actuals_filename=args.actuals_filename, |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame] | 375 | exception_handler=exception_handler, |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 376 | add_new=args.add_new) |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 377 | else: |
epoger@google.com | 89fa4b9 | 2013-07-10 16:54:10 +0000 | [diff] [blame] | 378 | # TODO(epoger): When we get rid of the ImageRebaseliner implementation, |
| 379 | # we should raise an Exception in this case (no JSON expectations file |
| 380 | # found to update), to prevent a recurrence of |
| 381 | # https://code.google.com/p/skia/issues/detail?id=1403 ('rebaseline.py |
| 382 | # script fails with misleading output when run outside of gm-expected |
| 383 | # dir') |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 384 | rebaseliner = rebaseline_imagefiles.ImageRebaseliner( |
| 385 | expectations_root=args.expectations_root, |
| 386 | tests=args.tests, configs=args.configs, |
| 387 | dry_run=args.dry_run, |
epoger@google.com | a783f2b | 2013-07-08 17:51:58 +0000 | [diff] [blame] | 388 | json_base_url=args.actuals_base_url, |
| 389 | json_filename=args.actuals_filename, |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame] | 390 | exception_handler=exception_handler, |
epoger@google.com | 99a8ec9 | 2013-06-19 18:56:59 +0000 | [diff] [blame] | 391 | add_new=args.add_new, |
| 392 | missing_json_is_fatal=missing_json_is_fatal) |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame] | 393 | |
epoger@google.com | 3e7399f | 2013-07-10 17:23:47 +0000 | [diff] [blame] | 394 | try: |
| 395 | rebaseliner.RebaselineSubdir(subdir=subdir, builder=builder) |
| 396 | except BaseException as e: |
epoger@google.com | ffcbdbf | 2013-07-16 17:35:39 +0000 | [diff] [blame] | 397 | exception_handler.RaiseExceptionOrContinue(e) |
| 398 | |
| 399 | exception_handler.ReportAllFailures() |