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. |
| 12 | Must be run from the gm-expected directory. If run from a git or SVN |
| 13 | checkout, the files will be added to the staging area for commit. |
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 | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 20 | import subprocess |
| 21 | import sys |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 22 | import urllib2 |
| 23 | |
| 24 | # Imports from within Skia |
| 25 | # |
epoger@google.com | dad5310 | 2013-06-12 14:25:30 +0000 | [diff] [blame] | 26 | # We need to add the 'gm' directory, so that we can import gm_json.py within |
| 27 | # that directory. That script allows us to parse the actual-results.json file |
| 28 | # written out by the GM tool. |
| 29 | # Make sure that the 'gm' dir is in the PYTHONPATH, but add it at the *end* |
| 30 | # so any dirs that are already in the PYTHONPATH will be preferred. |
| 31 | # |
| 32 | # This assumes that the 'gm' directory has been checked out as a sibling of |
| 33 | # the 'tools' directory containing this script, which will be the case if |
| 34 | # 'trunk' was checked out as a single unit. |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 35 | GM_DIRECTORY = os.path.realpath( |
| 36 | os.path.join(os.path.dirname(os.path.dirname(__file__)), 'gm')) |
| 37 | if GM_DIRECTORY not in sys.path: |
| 38 | sys.path.append(GM_DIRECTORY) |
| 39 | import gm_json |
| 40 | |
senorblanco@chromium.org | 782f3b4 | 2012-10-29 18:06:26 +0000 | [diff] [blame] | 41 | |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 42 | # Mapping of gm-expectations subdir (under |
| 43 | # https://skia.googlecode.com/svn/gm-expected/ ) |
| 44 | # 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] | 45 | SUBDIR_MAPPING = { |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 46 | 'base-shuttle-win7-intel-float': |
| 47 | 'Test-Win7-ShuttleA-HD2000-x86-Release', |
| 48 | 'base-shuttle-win7-intel-angle': |
| 49 | 'Test-Win7-ShuttleA-HD2000-x86-Release-ANGLE', |
| 50 | 'base-shuttle-win7-intel-directwrite': |
| 51 | 'Test-Win7-ShuttleA-HD2000-x86-Release-DirectWrite', |
| 52 | 'base-shuttle_ubuntu12_ati5770': |
| 53 | 'Test-Ubuntu12-ShuttleA-ATI5770-x86_64-Release', |
| 54 | 'base-macmini': |
| 55 | 'Test-Mac10.6-MacMini4.1-GeForce320M-x86-Release', |
| 56 | 'base-macmini-lion-float': |
| 57 | 'Test-Mac10.7-MacMini4.1-GeForce320M-x86-Release', |
| 58 | 'base-android-galaxy-nexus': |
| 59 | 'Test-Android-GalaxyNexus-SGX540-Arm7-Debug', |
| 60 | 'base-android-nexus-7': |
| 61 | 'Test-Android-Nexus7-Tegra3-Arm7-Release', |
| 62 | 'base-android-nexus-s': |
| 63 | 'Test-Android-NexusS-SGX540-Arm7-Release', |
| 64 | 'base-android-xoom': |
| 65 | 'Test-Android-Xoom-Tegra2-Arm7-Release', |
| 66 | 'base-android-nexus-10': |
| 67 | 'Test-Android-Nexus10-MaliT604-Arm7-Release', |
| 68 | } |
| 69 | |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 70 | |
epoger@google.com | db29a31 | 2013-06-04 14:58:47 +0000 | [diff] [blame] | 71 | class CommandFailedException(Exception): |
| 72 | pass |
| 73 | |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 74 | class Rebaseliner(object): |
| 75 | |
| 76 | # params: |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 77 | # json_base_url: base URL from which to read json_filename |
| 78 | # json_filename: filename (under json_base_url) from which to read a |
| 79 | # summary of results; typically "actual-results.json" |
| 80 | # subdirs: which platform subdirectories to rebaseline; if not specified, |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 81 | # rebaseline all platform subdirectories |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 82 | # tests: list of tests to rebaseline, or None if we should rebaseline |
| 83 | # whatever files the JSON results summary file tells us to |
| 84 | # configs: which configs to run for each test; this should only be |
| 85 | # specified if the list of tests was also specified (otherwise, |
| 86 | # the JSON file will give us test names and configs) |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 87 | # dry_run: if True, instead of actually downloading files or adding |
| 88 | # files to checkout, display a list of operations that |
| 89 | # we would normally perform |
epoger@google.com | dad5310 | 2013-06-12 14:25:30 +0000 | [diff] [blame] | 90 | # add_new: if True, add expectations for tests which don't have any yet |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 91 | def __init__(self, json_base_url, json_filename, |
epoger@google.com | dad5310 | 2013-06-12 14:25:30 +0000 | [diff] [blame] | 92 | subdirs=None, tests=None, configs=None, dry_run=False, |
| 93 | add_new=False): |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 94 | if configs and not tests: |
| 95 | raise ValueError('configs should only be specified if tests ' + |
| 96 | 'were specified also') |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 97 | self._tests = tests |
| 98 | self._configs = configs |
| 99 | if not subdirs: |
| 100 | self._subdirs = sorted(SUBDIR_MAPPING.keys()) |
epoger@google.com | bda4e91 | 2013-06-11 16:16:02 +0000 | [diff] [blame] | 101 | self._missing_json_is_fatal = False |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 102 | else: |
| 103 | self._subdirs = subdirs |
epoger@google.com | bda4e91 | 2013-06-11 16:16:02 +0000 | [diff] [blame] | 104 | self._missing_json_is_fatal = True |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 105 | self._json_base_url = json_base_url |
| 106 | self._json_filename = json_filename |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 107 | self._dry_run = dry_run |
epoger@google.com | dad5310 | 2013-06-12 14:25:30 +0000 | [diff] [blame] | 108 | self._add_new = add_new |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame^] | 109 | self._googlestorage_gm_actuals_root = ( |
| 110 | 'http://chromium-skia-gm.commondatastorage.googleapis.com/gm') |
| 111 | self._testname_pattern = re.compile('(\S+)_(\S+).png') |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 112 | self._is_svn_checkout = ( |
| 113 | os.path.exists('.svn') or |
| 114 | os.path.exists(os.path.join(os.pardir, '.svn'))) |
| 115 | self._is_git_checkout = ( |
| 116 | os.path.exists('.git') or |
| 117 | os.path.exists(os.path.join(os.pardir, '.git'))) |
| 118 | |
epoger@google.com | db29a31 | 2013-06-04 14:58:47 +0000 | [diff] [blame] | 119 | # If dry_run is False, execute subprocess.call(cmd). |
| 120 | # If dry_run is True, print the command we would have otherwise run. |
| 121 | # Raises a CommandFailedException if the command fails. |
| 122 | def _Call(self, cmd): |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 123 | if self._dry_run: |
| 124 | print '%s' % ' '.join(cmd) |
epoger@google.com | db29a31 | 2013-06-04 14:58:47 +0000 | [diff] [blame] | 125 | return |
| 126 | if subprocess.call(cmd) != 0: |
| 127 | raise CommandFailedException('error running command: ' + |
| 128 | ' '.join(cmd)) |
| 129 | |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame^] | 130 | # Download a single actual result from GoogleStorage, returning True if it |
| 131 | # succeeded. |
| 132 | def _DownloadFromGoogleStorage(self, infilename, outfilename, all_results): |
| 133 | test_name = self._testname_pattern.match(infilename).group(1) |
| 134 | if not test_name: |
| 135 | print '# unable to find test_name for infilename %s' % infilename |
| 136 | return False |
| 137 | try: |
| 138 | hash_type, hash_value = all_results[infilename] |
| 139 | except KeyError: |
| 140 | print ('# unable to find filename %s in all_results dict' % |
| 141 | infilename) |
| 142 | return False |
| 143 | url = '%s/%s/%s/%s.png' % (self._googlestorage_gm_actuals_root, |
| 144 | hash_type, test_name, hash_value) |
| 145 | try: |
| 146 | self._DownloadFile(source_url=url, dest_filename=outfilename) |
| 147 | return True |
| 148 | except CommandFailedException: |
| 149 | print '# Couldn\'t fetch gs_url %s' % url |
| 150 | return False |
| 151 | |
| 152 | # Download a single actual result from skia-autogen, returning True if it |
| 153 | # succeeded. |
| 154 | def _DownloadFromAutogen(self, infilename, outfilename, |
| 155 | expectations_subdir, builder_name): |
| 156 | url = ('http://skia-autogen.googlecode.com/svn/gm-actual/' + |
| 157 | expectations_subdir + '/' + builder_name + '/' + |
| 158 | expectations_subdir + '/' + infilename) |
| 159 | try: |
| 160 | self._DownloadFile(source_url=url, dest_filename=outfilename) |
| 161 | return True |
| 162 | except CommandFailedException: |
| 163 | print '# Couldn\'t fetch autogen_url %s' % url |
| 164 | return False |
| 165 | |
epoger@google.com | db29a31 | 2013-06-04 14:58:47 +0000 | [diff] [blame] | 166 | # Download a single file, raising a CommandFailedException if it fails. |
| 167 | def _DownloadFile(self, source_url, dest_filename): |
| 168 | # Download into a temporary file and then rename it afterwards, |
| 169 | # so that we don't corrupt the existing file if it fails midway thru. |
| 170 | temp_filename = os.path.join(os.path.dirname(dest_filename), |
| 171 | '.temp-' + os.path.basename(dest_filename)) |
| 172 | |
| 173 | # TODO(epoger): Replace calls to "curl"/"mv" (which will only work on |
| 174 | # Unix) with a Python HTTP library (which should work cross-platform) |
| 175 | self._Call([ 'curl', '--fail', '--silent', source_url, |
| 176 | '--output', temp_filename ]) |
| 177 | self._Call([ 'mv', temp_filename, dest_filename ]) |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 178 | |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 179 | # Returns the full contents of a URL, as a single string. |
| 180 | # |
| 181 | # Unlike standard URL handling, we allow relative "file:" URLs; |
| 182 | # for example, "file:one/two" resolves to the file ./one/two |
| 183 | # (relative to current working dir) |
| 184 | def _GetContentsOfUrl(self, url): |
| 185 | file_prefix = 'file:' |
| 186 | if url.startswith(file_prefix): |
| 187 | filename = url[len(file_prefix):] |
| 188 | return open(filename, 'r').read() |
| 189 | else: |
| 190 | return urllib2.urlopen(url).read() |
| 191 | |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame^] | 192 | # Returns a dictionary of actual results from actual-results.json file. |
| 193 | # |
| 194 | # The dictionary returned has this format: |
| 195 | # { |
| 196 | # u'imageblur_565.png': [u'bitmap-64bitMD5', 3359963596899141322], |
| 197 | # u'imageblur_8888.png': [u'bitmap-64bitMD5', 4217923806027861152], |
| 198 | # u'shadertext3_8888.png': [u'bitmap-64bitMD5', 3713708307125704716] |
| 199 | # } |
| 200 | # |
| 201 | # If the JSON actual result summary file cannot be loaded, the behavior |
| 202 | # depends on self._missing_json_is_fatal: |
| 203 | # - if true: execution will halt with an exception |
| 204 | # - if false: we will log an error message but return an empty dictionary |
| 205 | # |
| 206 | # params: |
| 207 | # json_url: URL pointing to a JSON actual result summary file |
| 208 | # sections: a list of section names to include in the results, e.g. |
| 209 | # [gm_json.JSONKEY_ACTUALRESULTS_FAILED, |
| 210 | # gm_json.JSONKEY_ACTUALRESULTS_NOCOMPARISON] ; |
| 211 | # if None, then include ALL sections. |
| 212 | def _GetActualResults(self, json_url, sections=None): |
| 213 | try: |
| 214 | json_contents = self._GetContentsOfUrl(json_url) |
| 215 | except (urllib2.HTTPError, IOError): |
| 216 | message = 'unable to load JSON summary URL %s' % json_url |
| 217 | if self._missing_json_is_fatal: |
| 218 | raise ValueError(message) |
| 219 | else: |
| 220 | print '# %s' % message |
| 221 | return {} |
| 222 | |
| 223 | json_dict = gm_json.LoadFromString(json_contents) |
| 224 | results_to_return = {} |
| 225 | actual_results = json_dict[gm_json.JSONKEY_ACTUALRESULTS] |
| 226 | if not sections: |
| 227 | sections = actual_results.keys() |
| 228 | for section in sections: |
| 229 | section_results = actual_results[section] |
| 230 | if section_results: |
| 231 | results_to_return.update(section_results) |
| 232 | return results_to_return |
| 233 | |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 234 | # Returns a list of files that require rebaselining. |
| 235 | # |
| 236 | # Note that this returns a list of FILES, like this: |
| 237 | # ['imageblur_565.png', 'xfermodes_pdf.png'] |
| 238 | # rather than a list of TESTS, like this: |
| 239 | # ['imageblur', 'xfermodes'] |
| 240 | # |
| 241 | # params: |
| 242 | # json_url: URL pointing to a JSON actual result summary file |
epoger@google.com | dad5310 | 2013-06-12 14:25:30 +0000 | [diff] [blame] | 243 | # add_new: if True, then return files listed in any of these sections: |
| 244 | # - JSONKEY_ACTUALRESULTS_FAILED |
| 245 | # - JSONKEY_ACTUALRESULTS_NOCOMPARISON |
| 246 | # if False, then return files listed in these sections: |
| 247 | # - JSONKEY_ACTUALRESULTS_FAILED |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 248 | # |
epoger@google.com | dad5310 | 2013-06-12 14:25:30 +0000 | [diff] [blame] | 249 | def _GetFilesToRebaseline(self, json_url, add_new): |
epoger@google.com | cc2e1cf | 2013-06-11 16:24:37 +0000 | [diff] [blame] | 250 | if self._dry_run: |
| 251 | print '' |
| 252 | print '#' |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 253 | print ('# Getting files to rebaseline from JSON summary URL %s ...' |
| 254 | % json_url) |
epoger@google.com | dad5310 | 2013-06-12 14:25:30 +0000 | [diff] [blame] | 255 | sections = [gm_json.JSONKEY_ACTUALRESULTS_FAILED] |
| 256 | if add_new: |
| 257 | sections.append(gm_json.JSONKEY_ACTUALRESULTS_NOCOMPARISON) |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame^] | 258 | results_to_rebaseline = self._GetActualResults(json_url=json_url, |
| 259 | sections=sections) |
| 260 | files_to_rebaseline = results_to_rebaseline.keys() |
| 261 | files_to_rebaseline.sort() |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 262 | print '# ... found files_to_rebaseline %s' % files_to_rebaseline |
epoger@google.com | cc2e1cf | 2013-06-11 16:24:37 +0000 | [diff] [blame] | 263 | if self._dry_run: |
| 264 | print '#' |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 265 | return files_to_rebaseline |
| 266 | |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 267 | # Rebaseline a single file. |
| 268 | def _RebaselineOneFile(self, expectations_subdir, builder_name, |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame^] | 269 | infilename, outfilename, all_results): |
epoger@google.com | cc2e1cf | 2013-06-11 16:24:37 +0000 | [diff] [blame] | 270 | if self._dry_run: |
| 271 | print '' |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 272 | print '# ' + infilename |
epoger@google.com | db29a31 | 2013-06-04 14:58:47 +0000 | [diff] [blame] | 273 | |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame^] | 274 | # First try to download this result image from Google Storage. |
| 275 | # If that fails, try skia-autogen. |
| 276 | # If that fails too, just go on to the next file. |
epoger@google.com | db29a31 | 2013-06-04 14:58:47 +0000 | [diff] [blame] | 277 | # |
| 278 | # This not treated as a fatal failure because not all |
| 279 | # platforms generate all configs (e.g., Android does not |
| 280 | # generate PDF). |
| 281 | # |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame^] | 282 | # TODO(epoger): Once we are downloading only files that the |
| 283 | # actual-results.json file told us to, this should become a |
| 284 | # fatal error. (If the actual-results.json file told us that |
| 285 | # the test failed with XXX results, we should be able to download |
| 286 | # those results every time.) |
| 287 | if not self._DownloadFromGoogleStorage(infilename=infilename, |
| 288 | outfilename=outfilename, |
| 289 | all_results=all_results): |
| 290 | if not self._DownloadFromAutogen(infilename=infilename, |
| 291 | outfilename=outfilename, |
| 292 | expectations_subdir=expectations_subdir, |
| 293 | builder_name=builder_name): |
| 294 | print '# Couldn\'t fetch infilename ' + infilename |
| 295 | return |
epoger@google.com | db29a31 | 2013-06-04 14:58:47 +0000 | [diff] [blame] | 296 | |
epoger@google.com | dad5310 | 2013-06-12 14:25:30 +0000 | [diff] [blame] | 297 | # Add this file to version control (if appropriate). |
| 298 | if self._add_new: |
| 299 | if self._is_svn_checkout: |
| 300 | cmd = [ 'svn', 'add', '--quiet', outfilename ] |
| 301 | self._Call(cmd) |
| 302 | cmd = [ 'svn', 'propset', '--quiet', 'svn:mime-type', |
| 303 | 'image/png', outfilename ]; |
| 304 | self._Call(cmd) |
| 305 | elif self._is_git_checkout: |
| 306 | cmd = [ 'git', 'add', outfilename ] |
| 307 | self._Call(cmd) |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 308 | |
| 309 | # Rebaseline the given configs for a single test. |
| 310 | # |
| 311 | # params: |
| 312 | # expectations_subdir |
| 313 | # builder_name |
| 314 | # test: a single test to rebaseline |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame^] | 315 | # all_results: a dictionary of all actual results |
| 316 | def _RebaselineOneTest(self, expectations_subdir, builder_name, test, |
| 317 | all_results): |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 318 | if self._configs: |
| 319 | configs = self._configs |
| 320 | else: |
| 321 | if (expectations_subdir == 'base-shuttle-win7-intel-angle'): |
| 322 | configs = [ 'angle', 'anglemsaa16' ] |
| 323 | else: |
| 324 | configs = [ '565', '8888', 'gpu', 'pdf', 'mesa', 'msaa16', |
| 325 | 'msaa4' ] |
epoger@google.com | cc2e1cf | 2013-06-11 16:24:37 +0000 | [diff] [blame] | 326 | if self._dry_run: |
| 327 | print '' |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 328 | print '# ' + expectations_subdir + ':' |
| 329 | for config in configs: |
| 330 | infilename = test + '_' + config + '.png' |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 331 | outfilename = os.path.join(expectations_subdir, infilename); |
| 332 | self._RebaselineOneFile(expectations_subdir=expectations_subdir, |
| 333 | builder_name=builder_name, |
| 334 | infilename=infilename, |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame^] | 335 | outfilename=outfilename, |
| 336 | all_results=all_results) |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 337 | |
| 338 | # Rebaseline all platforms/tests/types we specified in the constructor. |
| 339 | def RebaselineAll(self): |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 340 | for subdir in self._subdirs: |
| 341 | if not subdir in SUBDIR_MAPPING.keys(): |
| 342 | raise Exception(('unrecognized platform subdir "%s"; ' + |
| 343 | 'should be one of %s') % ( |
| 344 | subdir, SUBDIR_MAPPING.keys())) |
| 345 | builder_name = SUBDIR_MAPPING[subdir] |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame^] | 346 | json_url = '/'.join([self._json_base_url, |
| 347 | subdir, builder_name, subdir, |
| 348 | self._json_filename]) |
| 349 | all_results = self._GetActualResults(json_url=json_url) |
| 350 | |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 351 | if self._tests: |
| 352 | for test in self._tests: |
| 353 | self._RebaselineOneTest(expectations_subdir=subdir, |
| 354 | builder_name=builder_name, |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame^] | 355 | test=test, all_results=all_results) |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 356 | else: # get the raw list of files that need rebaselining from JSON |
epoger@google.com | dad5310 | 2013-06-12 14:25:30 +0000 | [diff] [blame] | 357 | filenames = self._GetFilesToRebaseline(json_url=json_url, |
| 358 | add_new=self._add_new) |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 359 | for filename in filenames: |
| 360 | outfilename = os.path.join(subdir, filename); |
| 361 | self._RebaselineOneFile(expectations_subdir=subdir, |
| 362 | builder_name=builder_name, |
| 363 | infilename=filename, |
epoger@google.com | e78d207 | 2013-06-12 17:44:14 +0000 | [diff] [blame^] | 364 | outfilename=outfilename, |
| 365 | all_results=all_results) |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 366 | |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 367 | # main... |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 368 | |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 369 | parser = argparse.ArgumentParser() |
epoger@google.com | dad5310 | 2013-06-12 14:25:30 +0000 | [diff] [blame] | 370 | parser.add_argument('--add-new', action='store_true', |
| 371 | help='in addition to the standard behavior of ' + |
| 372 | 'updating expectations for failing tests, add ' + |
| 373 | 'expectations for tests which don\'t have expectations ' + |
| 374 | 'yet.') |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 375 | parser.add_argument('--configs', metavar='CONFIG', nargs='+', |
| 376 | help='which configurations to rebaseline, e.g. ' + |
| 377 | '"--configs 565 8888"; if unspecified, run a default ' + |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 378 | 'set of configs. This should ONLY be specified if ' + |
| 379 | '--tests has also been specified.') |
epoger@google.com | 82f3178 | 2013-06-11 15:45:46 +0000 | [diff] [blame] | 380 | parser.add_argument('--dry-run', action='store_true', |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 381 | help='instead of actually downloading files or adding ' + |
| 382 | 'files to checkout, display a list of operations that ' + |
| 383 | 'we would normally perform') |
epoger@google.com | 82f3178 | 2013-06-11 15:45:46 +0000 | [diff] [blame] | 384 | parser.add_argument('--json-base-url', |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 385 | help='base URL from which to read JSON_FILENAME ' + |
| 386 | 'files; defaults to %(default)s', |
| 387 | default='http://skia-autogen.googlecode.com/svn/gm-actual') |
epoger@google.com | 82f3178 | 2013-06-11 15:45:46 +0000 | [diff] [blame] | 388 | parser.add_argument('--json-filename', |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 389 | help='filename (under JSON_BASE_URL) to read a summary ' + |
| 390 | 'of results from; defaults to %(default)s', |
| 391 | default='actual-results.json') |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 392 | parser.add_argument('--subdirs', metavar='SUBDIR', nargs='+', |
| 393 | help='which platform subdirectories to rebaseline; ' + |
| 394 | 'if unspecified, rebaseline all subdirs, same as ' + |
| 395 | '"--subdirs %s"' % ' '.join(sorted(SUBDIR_MAPPING.keys()))) |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 396 | parser.add_argument('--tests', metavar='TEST', nargs='+', |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 397 | help='which tests to rebaseline, e.g. ' + |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 398 | '"--tests aaclip bigmatrix"; if unspecified, then all ' + |
| 399 | 'failing tests (according to the actual-results.json ' + |
| 400 | 'file) will be rebaselined.') |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 401 | args = parser.parse_args() |
| 402 | rebaseliner = Rebaseliner(tests=args.tests, configs=args.configs, |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame] | 403 | subdirs=args.subdirs, dry_run=args.dry_run, |
| 404 | json_base_url=args.json_base_url, |
epoger@google.com | dad5310 | 2013-06-12 14:25:30 +0000 | [diff] [blame] | 405 | json_filename=args.json_filename, |
| 406 | add_new=args.add_new) |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 407 | rebaseliner.RebaselineAll() |