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 |
| 19 | import subprocess |
| 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 | # |
| 25 | # Make sure that they are in the PYTHONPATH, but add them at the *end* |
| 26 | # so any that are already in the PYTHONPATH will be preferred. |
| 27 | GM_DIRECTORY = os.path.realpath( |
| 28 | os.path.join(os.path.dirname(os.path.dirname(__file__)), 'gm')) |
| 29 | if GM_DIRECTORY not in sys.path: |
| 30 | sys.path.append(GM_DIRECTORY) |
| 31 | import gm_json |
| 32 | |
senorblanco@chromium.org | 782f3b4 | 2012-10-29 18:06:26 +0000 | [diff] [blame] | 33 | |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 34 | # Mapping of gm-expectations subdir (under |
| 35 | # https://skia.googlecode.com/svn/gm-expected/ ) |
| 36 | # 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] | 37 | SUBDIR_MAPPING = { |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 38 | 'base-shuttle-win7-intel-float': |
| 39 | 'Test-Win7-ShuttleA-HD2000-x86-Release', |
| 40 | 'base-shuttle-win7-intel-angle': |
| 41 | 'Test-Win7-ShuttleA-HD2000-x86-Release-ANGLE', |
| 42 | 'base-shuttle-win7-intel-directwrite': |
| 43 | 'Test-Win7-ShuttleA-HD2000-x86-Release-DirectWrite', |
| 44 | 'base-shuttle_ubuntu12_ati5770': |
| 45 | 'Test-Ubuntu12-ShuttleA-ATI5770-x86_64-Release', |
| 46 | 'base-macmini': |
| 47 | 'Test-Mac10.6-MacMini4.1-GeForce320M-x86-Release', |
| 48 | 'base-macmini-lion-float': |
| 49 | 'Test-Mac10.7-MacMini4.1-GeForce320M-x86-Release', |
| 50 | 'base-android-galaxy-nexus': |
| 51 | 'Test-Android-GalaxyNexus-SGX540-Arm7-Debug', |
| 52 | 'base-android-nexus-7': |
| 53 | 'Test-Android-Nexus7-Tegra3-Arm7-Release', |
| 54 | 'base-android-nexus-s': |
| 55 | 'Test-Android-NexusS-SGX540-Arm7-Release', |
| 56 | 'base-android-xoom': |
| 57 | 'Test-Android-Xoom-Tegra2-Arm7-Release', |
| 58 | 'base-android-nexus-10': |
| 59 | 'Test-Android-Nexus10-MaliT604-Arm7-Release', |
| 60 | } |
| 61 | |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 62 | |
epoger@google.com | db29a31 | 2013-06-04 14:58:47 +0000 | [diff] [blame] | 63 | class CommandFailedException(Exception): |
| 64 | pass |
| 65 | |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 66 | class Rebaseliner(object): |
| 67 | |
| 68 | # params: |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame^] | 69 | # json_base_url: base URL from which to read json_filename |
| 70 | # json_filename: filename (under json_base_url) from which to read a |
| 71 | # summary of results; typically "actual-results.json" |
| 72 | # subdirs: which platform subdirectories to rebaseline; if not specified, |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 73 | # rebaseline all platform subdirectories |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame^] | 74 | # tests: list of tests to rebaseline, or None if we should rebaseline |
| 75 | # whatever files the JSON results summary file tells us to |
| 76 | # configs: which configs to run for each test; this should only be |
| 77 | # specified if the list of tests was also specified (otherwise, |
| 78 | # the JSON file will give us test names and configs) |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 79 | # dry_run: if True, instead of actually downloading files or adding |
| 80 | # files to checkout, display a list of operations that |
| 81 | # we would normally perform |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame^] | 82 | def __init__(self, json_base_url, json_filename, |
| 83 | subdirs=None, tests=None, configs=None, dry_run=False): |
| 84 | if configs and not tests: |
| 85 | raise ValueError('configs should only be specified if tests ' + |
| 86 | 'were specified also') |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 87 | self._tests = tests |
| 88 | self._configs = configs |
| 89 | if not subdirs: |
| 90 | self._subdirs = sorted(SUBDIR_MAPPING.keys()) |
| 91 | else: |
| 92 | self._subdirs = subdirs |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame^] | 93 | self._json_base_url = json_base_url |
| 94 | self._json_filename = json_filename |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 95 | self._dry_run = dry_run |
| 96 | self._is_svn_checkout = ( |
| 97 | os.path.exists('.svn') or |
| 98 | os.path.exists(os.path.join(os.pardir, '.svn'))) |
| 99 | self._is_git_checkout = ( |
| 100 | os.path.exists('.git') or |
| 101 | os.path.exists(os.path.join(os.pardir, '.git'))) |
| 102 | |
epoger@google.com | db29a31 | 2013-06-04 14:58:47 +0000 | [diff] [blame] | 103 | # If dry_run is False, execute subprocess.call(cmd). |
| 104 | # If dry_run is True, print the command we would have otherwise run. |
| 105 | # Raises a CommandFailedException if the command fails. |
| 106 | def _Call(self, cmd): |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 107 | if self._dry_run: |
| 108 | print '%s' % ' '.join(cmd) |
epoger@google.com | db29a31 | 2013-06-04 14:58:47 +0000 | [diff] [blame] | 109 | return |
| 110 | if subprocess.call(cmd) != 0: |
| 111 | raise CommandFailedException('error running command: ' + |
| 112 | ' '.join(cmd)) |
| 113 | |
| 114 | # Download a single file, raising a CommandFailedException if it fails. |
| 115 | def _DownloadFile(self, source_url, dest_filename): |
| 116 | # Download into a temporary file and then rename it afterwards, |
| 117 | # so that we don't corrupt the existing file if it fails midway thru. |
| 118 | temp_filename = os.path.join(os.path.dirname(dest_filename), |
| 119 | '.temp-' + os.path.basename(dest_filename)) |
| 120 | |
| 121 | # TODO(epoger): Replace calls to "curl"/"mv" (which will only work on |
| 122 | # Unix) with a Python HTTP library (which should work cross-platform) |
| 123 | self._Call([ 'curl', '--fail', '--silent', source_url, |
| 124 | '--output', temp_filename ]) |
| 125 | self._Call([ 'mv', temp_filename, dest_filename ]) |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 126 | |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame^] | 127 | # Returns the full contents of a URL, as a single string. |
| 128 | # |
| 129 | # Unlike standard URL handling, we allow relative "file:" URLs; |
| 130 | # for example, "file:one/two" resolves to the file ./one/two |
| 131 | # (relative to current working dir) |
| 132 | def _GetContentsOfUrl(self, url): |
| 133 | file_prefix = 'file:' |
| 134 | if url.startswith(file_prefix): |
| 135 | filename = url[len(file_prefix):] |
| 136 | return open(filename, 'r').read() |
| 137 | else: |
| 138 | return urllib2.urlopen(url).read() |
| 139 | |
| 140 | # Returns a list of files that require rebaselining. |
| 141 | # |
| 142 | # Note that this returns a list of FILES, like this: |
| 143 | # ['imageblur_565.png', 'xfermodes_pdf.png'] |
| 144 | # rather than a list of TESTS, like this: |
| 145 | # ['imageblur', 'xfermodes'] |
| 146 | # |
| 147 | # params: |
| 148 | # json_url: URL pointing to a JSON actual result summary file |
| 149 | # |
| 150 | # TODO(epoger): add a parameter indicating whether "no-comparison" |
| 151 | # results (those for which we don't have any expectations yet) |
| 152 | # should be rebaselined. For now, we only return failed expectations. |
| 153 | def _GetFilesToRebaseline(self, json_url): |
| 154 | print ('# Getting files to rebaseline from JSON summary URL %s ...' |
| 155 | % json_url) |
| 156 | json_contents = self._GetContentsOfUrl(json_url) |
| 157 | json_dict = gm_json.LoadFromString(json_contents) |
| 158 | actual_results = json_dict[gm_json.JSONKEY_ACTUALRESULTS] |
| 159 | |
| 160 | files_to_rebaseline = [] |
| 161 | failed_results = actual_results[gm_json.JSONKEY_ACTUALRESULTS_FAILED] |
| 162 | if failed_results: |
| 163 | files_to_rebaseline.extend(failed_results.keys()) |
| 164 | |
| 165 | print '# ... found files_to_rebaseline %s' % files_to_rebaseline |
| 166 | return files_to_rebaseline |
| 167 | |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 168 | # Rebaseline a single file. |
| 169 | def _RebaselineOneFile(self, expectations_subdir, builder_name, |
| 170 | infilename, outfilename): |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame^] | 171 | print '# ' + infilename |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 172 | url = ('http://skia-autogen.googlecode.com/svn/gm-actual/' + |
| 173 | expectations_subdir + '/' + builder_name + '/' + |
| 174 | expectations_subdir + '/' + infilename) |
epoger@google.com | db29a31 | 2013-06-04 14:58:47 +0000 | [diff] [blame] | 175 | |
| 176 | # Try to download this file, but if that fails, keep going... |
| 177 | # |
| 178 | # This not treated as a fatal failure because not all |
| 179 | # platforms generate all configs (e.g., Android does not |
| 180 | # generate PDF). |
| 181 | # |
| 182 | # We could tweak the list of configs within this tool to |
| 183 | # reflect which combinations the bots actually generate, and |
| 184 | # then fail if any of those expected combinations are |
| 185 | # missing... but then this tool would become useless every |
| 186 | # time someone tweaked the configs on the bots without |
| 187 | # updating this script. |
| 188 | try: |
| 189 | self._DownloadFile(source_url=url, dest_filename=outfilename) |
| 190 | except CommandFailedException: |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 191 | print '# Couldn\'t fetch ' + url |
| 192 | return |
epoger@google.com | db29a31 | 2013-06-04 14:58:47 +0000 | [diff] [blame] | 193 | |
| 194 | # Add this file to version control (if it isn't already). |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 195 | if self._is_svn_checkout: |
| 196 | cmd = [ 'svn', 'add', '--quiet', outfilename ] |
| 197 | self._Call(cmd) |
| 198 | cmd = [ 'svn', 'propset', '--quiet', 'svn:mime-type', 'image/png', |
| 199 | outfilename ]; |
| 200 | self._Call(cmd) |
| 201 | elif self._is_git_checkout: |
| 202 | cmd = [ 'git', 'add', outfilename ] |
| 203 | self._Call(cmd) |
| 204 | |
| 205 | # Rebaseline the given configs for a single test. |
| 206 | # |
| 207 | # params: |
| 208 | # expectations_subdir |
| 209 | # builder_name |
| 210 | # test: a single test to rebaseline |
| 211 | def _RebaselineOneTest(self, expectations_subdir, builder_name, test): |
| 212 | if self._configs: |
| 213 | configs = self._configs |
| 214 | else: |
| 215 | if (expectations_subdir == 'base-shuttle-win7-intel-angle'): |
| 216 | configs = [ 'angle', 'anglemsaa16' ] |
| 217 | else: |
| 218 | configs = [ '565', '8888', 'gpu', 'pdf', 'mesa', 'msaa16', |
| 219 | 'msaa4' ] |
| 220 | print '# ' + expectations_subdir + ':' |
| 221 | for config in configs: |
| 222 | infilename = test + '_' + config + '.png' |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 223 | outfilename = os.path.join(expectations_subdir, infilename); |
| 224 | self._RebaselineOneFile(expectations_subdir=expectations_subdir, |
| 225 | builder_name=builder_name, |
| 226 | infilename=infilename, |
| 227 | outfilename=outfilename) |
| 228 | |
| 229 | # Rebaseline all platforms/tests/types we specified in the constructor. |
| 230 | def RebaselineAll(self): |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame^] | 231 | for subdir in self._subdirs: |
| 232 | if not subdir in SUBDIR_MAPPING.keys(): |
| 233 | raise Exception(('unrecognized platform subdir "%s"; ' + |
| 234 | 'should be one of %s') % ( |
| 235 | subdir, SUBDIR_MAPPING.keys())) |
| 236 | builder_name = SUBDIR_MAPPING[subdir] |
| 237 | if self._tests: |
| 238 | for test in self._tests: |
| 239 | self._RebaselineOneTest(expectations_subdir=subdir, |
| 240 | builder_name=builder_name, |
| 241 | test=test) |
| 242 | else: # get the raw list of files that need rebaselining from JSON |
| 243 | json_url = '/'.join([self._json_base_url, |
| 244 | subdir, builder_name, subdir, |
| 245 | self._json_filename]) |
| 246 | filenames = self._GetFilesToRebaseline(json_url=json_url) |
| 247 | for filename in filenames: |
| 248 | outfilename = os.path.join(subdir, filename); |
| 249 | self._RebaselineOneFile(expectations_subdir=subdir, |
| 250 | builder_name=builder_name, |
| 251 | infilename=filename, |
| 252 | outfilename=outfilename) |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 253 | |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 254 | # main... |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 255 | |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 256 | parser = argparse.ArgumentParser() |
| 257 | parser.add_argument('--configs', metavar='CONFIG', nargs='+', |
| 258 | help='which configurations to rebaseline, e.g. ' + |
| 259 | '"--configs 565 8888"; if unspecified, run a default ' + |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame^] | 260 | 'set of configs. This should ONLY be specified if ' + |
| 261 | '--tests has also been specified.') |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 262 | parser.add_argument('--dry_run', action='store_true', |
| 263 | help='instead of actually downloading files or adding ' + |
| 264 | 'files to checkout, display a list of operations that ' + |
| 265 | 'we would normally perform') |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame^] | 266 | parser.add_argument('--json_base_url', |
| 267 | help='base URL from which to read JSON_FILENAME ' + |
| 268 | 'files; defaults to %(default)s', |
| 269 | default='http://skia-autogen.googlecode.com/svn/gm-actual') |
| 270 | parser.add_argument('--json_filename', |
| 271 | help='filename (under JSON_BASE_URL) to read a summary ' + |
| 272 | 'of results from; defaults to %(default)s', |
| 273 | default='actual-results.json') |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 274 | parser.add_argument('--subdirs', metavar='SUBDIR', nargs='+', |
| 275 | help='which platform subdirectories to rebaseline; ' + |
| 276 | 'if unspecified, rebaseline all subdirs, same as ' + |
| 277 | '"--subdirs %s"' % ' '.join(sorted(SUBDIR_MAPPING.keys()))) |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame^] | 278 | parser.add_argument('--tests', metavar='TEST', nargs='+', |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 279 | help='which tests to rebaseline, e.g. ' + |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame^] | 280 | '"--tests aaclip bigmatrix"; if unspecified, then all ' + |
| 281 | 'failing tests (according to the actual-results.json ' + |
| 282 | 'file) will be rebaselined.') |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 283 | args = parser.parse_args() |
| 284 | rebaseliner = Rebaseliner(tests=args.tests, configs=args.configs, |
epoger@google.com | 99ba65a | 2013-06-05 15:43:37 +0000 | [diff] [blame^] | 285 | subdirs=args.subdirs, dry_run=args.dry_run, |
| 286 | json_base_url=args.json_base_url, |
| 287 | json_filename=args.json_filename) |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 288 | rebaseliner.RebaselineAll() |