| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 ''' | 3 ''' |
| 4 Copyright 2012 Google Inc. | 4 Copyright 2012 Google Inc. |
| 5 | 5 |
| 6 Use of this source code is governed by a BSD-style license that can be | 6 Use of this source code is governed by a BSD-style license that can be |
| 7 found in the LICENSE file. | 7 found in the LICENSE file. |
| 8 ''' | 8 ''' |
| 9 | 9 |
| 10 ''' | 10 ''' |
| 11 Rebaselines the given GM tests, on all bots and all configurations. | 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 | 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. | 13 checkout, the files will be added to the staging area for commit. |
| 14 ''' | 14 ''' |
| 15 | 15 |
| 16 import argparse | 16 import argparse |
| 17 import os | 17 import os |
| 18 import subprocess | 18 import subprocess |
| 19 import sys | 19 import sys |
| 20 import tempfile | |
| 21 | 20 |
| 22 # Mapping of gm-expectations subdir (under | 21 # Mapping of gm-expectations subdir (under |
| 23 # https://skia.googlecode.com/svn/gm-expected/ ) | 22 # https://skia.googlecode.com/svn/gm-expected/ ) |
| 24 # to builder name (see list at http://108.170.217.252:10117/builders ) | 23 # to builder name (see list at http://108.170.217.252:10117/builders ) |
| 25 SUBDIR_MAPPING = { | 24 SUBDIR_MAPPING = { |
| 26 'base-shuttle-win7-intel-float': | 25 'base-shuttle-win7-intel-float': |
| 27 'Test-Win7-ShuttleA-HD2000-x86-Release', | 26 'Test-Win7-ShuttleA-HD2000-x86-Release', |
| 28 'base-shuttle-win7-intel-angle': | 27 'base-shuttle-win7-intel-angle': |
| 29 'Test-Win7-ShuttleA-HD2000-x86-Release-ANGLE', | 28 'Test-Win7-ShuttleA-HD2000-x86-Release-ANGLE', |
| 30 'base-shuttle-win7-intel-directwrite': | 29 'base-shuttle-win7-intel-directwrite': |
| (...skipping 10 matching lines...) Expand all Loading... |
| 41 'Test-Android-Nexus7-Tegra3-Arm7-Release', | 40 'Test-Android-Nexus7-Tegra3-Arm7-Release', |
| 42 'base-android-nexus-s': | 41 'base-android-nexus-s': |
| 43 'Test-Android-NexusS-SGX540-Arm7-Release', | 42 'Test-Android-NexusS-SGX540-Arm7-Release', |
| 44 'base-android-xoom': | 43 'base-android-xoom': |
| 45 'Test-Android-Xoom-Tegra2-Arm7-Release', | 44 'Test-Android-Xoom-Tegra2-Arm7-Release', |
| 46 'base-android-nexus-10': | 45 'base-android-nexus-10': |
| 47 'Test-Android-Nexus10-MaliT604-Arm7-Release', | 46 'Test-Android-Nexus10-MaliT604-Arm7-Release', |
| 48 } | 47 } |
| 49 | 48 |
| 50 | 49 |
| 50 class CommandFailedException(Exception): |
| 51 pass |
| 52 |
| 51 class Rebaseliner(object): | 53 class Rebaseliner(object): |
| 52 | 54 |
| 53 # params: | 55 # params: |
| 54 # tests: list of tests to rebaseline | 56 # tests: list of tests to rebaseline |
| 55 # configs: which configs to run for each test | 57 # configs: which configs to run for each test |
| 56 # subdirs: which platform subdirectories to rebaseline; if an empty list, | 58 # subdirs: which platform subdirectories to rebaseline; if an empty list, |
| 57 # rebaseline all platform subdirectories | 59 # rebaseline all platform subdirectories |
| 58 # dry_run: if True, instead of actually downloading files or adding | 60 # dry_run: if True, instead of actually downloading files or adding |
| 59 # files to checkout, display a list of operations that | 61 # files to checkout, display a list of operations that |
| 60 # we would normally perform | 62 # we would normally perform |
| 61 def __init__(self, tests, configs=[], subdirs=[], dry_run=False): | 63 def __init__(self, tests, configs=[], subdirs=[], dry_run=False): |
| 62 if not tests: | 64 if not tests: |
| 63 raise Exception('at least one test must be specified') | 65 raise Exception('at least one test must be specified') |
| 64 self._tests = tests | 66 self._tests = tests |
| 65 self._configs = configs | 67 self._configs = configs |
| 66 if not subdirs: | 68 if not subdirs: |
| 67 self._subdirs = sorted(SUBDIR_MAPPING.keys()) | 69 self._subdirs = sorted(SUBDIR_MAPPING.keys()) |
| 68 else: | 70 else: |
| 69 self._subdirs = subdirs | 71 self._subdirs = subdirs |
| 70 self._dry_run = dry_run | 72 self._dry_run = dry_run |
| 71 self._is_svn_checkout = ( | 73 self._is_svn_checkout = ( |
| 72 os.path.exists('.svn') or | 74 os.path.exists('.svn') or |
| 73 os.path.exists(os.path.join(os.pardir, '.svn'))) | 75 os.path.exists(os.path.join(os.pardir, '.svn'))) |
| 74 self._is_git_checkout = ( | 76 self._is_git_checkout = ( |
| 75 os.path.exists('.git') or | 77 os.path.exists('.git') or |
| 76 os.path.exists(os.path.join(os.pardir, '.git'))) | 78 os.path.exists(os.path.join(os.pardir, '.git'))) |
| 77 | 79 |
| 78 # Execute subprocess.call(), unless dry_run is True | 80 # If dry_run is False, execute subprocess.call(cmd). |
| 79 def _Call(self, cmd, stdout=None): | 81 # If dry_run is True, print the command we would have otherwise run. |
| 82 # Raises a CommandFailedException if the command fails. |
| 83 def _Call(self, cmd): |
| 80 if self._dry_run: | 84 if self._dry_run: |
| 81 print '%s' % ' '.join(cmd) | 85 print '%s' % ' '.join(cmd) |
| 82 return 0 | 86 return |
| 83 if stdout: | 87 if subprocess.call(cmd) != 0: |
| 84 return subprocess.call(cmd, stdout=stdout) | 88 raise CommandFailedException('error running command: ' + |
| 85 else: | 89 ' '.join(cmd)) |
| 86 return subprocess.call(cmd) | 90 |
| 91 # Download a single file, raising a CommandFailedException if it fails. |
| 92 def _DownloadFile(self, source_url, dest_filename): |
| 93 # Download into a temporary file and then rename it afterwards, |
| 94 # so that we don't corrupt the existing file if it fails midway thru. |
| 95 temp_filename = os.path.join(os.path.dirname(dest_filename), |
| 96 '.temp-' + os.path.basename(dest_filename)) |
| 97 |
| 98 # TODO(epoger): Replace calls to "curl"/"mv" (which will only work on |
| 99 # Unix) with a Python HTTP library (which should work cross-platform) |
| 100 self._Call([ 'curl', '--fail', '--silent', source_url, |
| 101 '--output', temp_filename ]) |
| 102 self._Call([ 'mv', temp_filename, dest_filename ]) |
| 87 | 103 |
| 88 # Rebaseline a single file. | 104 # Rebaseline a single file. |
| 89 def _RebaselineOneFile(self, expectations_subdir, builder_name, | 105 def _RebaselineOneFile(self, expectations_subdir, builder_name, |
| 90 infilename, outfilename): | 106 infilename, outfilename): |
| 91 url = ('http://skia-autogen.googlecode.com/svn/gm-actual/' + | 107 url = ('http://skia-autogen.googlecode.com/svn/gm-actual/' + |
| 92 expectations_subdir + '/' + builder_name + '/' + | 108 expectations_subdir + '/' + builder_name + '/' + |
| 93 expectations_subdir + '/' + infilename) | 109 expectations_subdir + '/' + infilename) |
| 94 cmd = [ 'curl', '--fail', '--silent', url ] | 110 |
| 95 temp = tempfile.NamedTemporaryFile() | 111 # Try to download this file, but if that fails, keep going... |
| 96 ret = self._Call(cmd, stdout=temp) | 112 # |
| 97 if ret != 0: | 113 # This not treated as a fatal failure because not all |
| 114 # platforms generate all configs (e.g., Android does not |
| 115 # generate PDF). |
| 116 # |
| 117 # We could tweak the list of configs within this tool to |
| 118 # reflect which combinations the bots actually generate, and |
| 119 # then fail if any of those expected combinations are |
| 120 # missing... but then this tool would become useless every |
| 121 # time someone tweaked the configs on the bots without |
| 122 # updating this script. |
| 123 try: |
| 124 self._DownloadFile(source_url=url, dest_filename=outfilename) |
| 125 except CommandFailedException: |
| 98 print '# Couldn\'t fetch ' + url | 126 print '# Couldn\'t fetch ' + url |
| 99 return | 127 return |
| 100 cmd = [ 'cp', temp.name, outfilename ] | 128 |
| 101 self._Call(cmd); | 129 # Add this file to version control (if it isn't already). |
| 102 if self._is_svn_checkout: | 130 if self._is_svn_checkout: |
| 103 cmd = [ 'svn', 'add', '--quiet', outfilename ] | 131 cmd = [ 'svn', 'add', '--quiet', outfilename ] |
| 104 self._Call(cmd) | 132 self._Call(cmd) |
| 105 cmd = [ 'svn', 'propset', '--quiet', 'svn:mime-type', 'image/png', | 133 cmd = [ 'svn', 'propset', '--quiet', 'svn:mime-type', 'image/png', |
| 106 outfilename ]; | 134 outfilename ]; |
| 107 self._Call(cmd) | 135 self._Call(cmd) |
| 108 elif self._is_git_checkout: | 136 elif self._is_git_checkout: |
| 109 cmd = [ 'git', 'add', outfilename ] | 137 cmd = [ 'git', 'add', outfilename ] |
| 110 self._Call(cmd) | 138 self._Call(cmd) |
| 111 | 139 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 help='which platform subdirectories to rebaseline; ' + | 191 help='which platform subdirectories to rebaseline; ' + |
| 164 'if unspecified, rebaseline all subdirs, same as ' + | 192 'if unspecified, rebaseline all subdirs, same as ' + |
| 165 '"--subdirs %s"' % ' '.join(sorted(SUBDIR_MAPPING.keys()))) | 193 '"--subdirs %s"' % ' '.join(sorted(SUBDIR_MAPPING.keys()))) |
| 166 parser.add_argument('--tests', metavar='TEST', nargs='+', required=True, | 194 parser.add_argument('--tests', metavar='TEST', nargs='+', required=True, |
| 167 help='which tests to rebaseline, e.g. ' + | 195 help='which tests to rebaseline, e.g. ' + |
| 168 '"--tests aaclip bigmatrix"') | 196 '"--tests aaclip bigmatrix"') |
| 169 args = parser.parse_args() | 197 args = parser.parse_args() |
| 170 rebaseliner = Rebaseliner(tests=args.tests, configs=args.configs, | 198 rebaseliner = Rebaseliner(tests=args.tests, configs=args.configs, |
| 171 subdirs=args.subdirs, dry_run=args.dry_run) | 199 subdirs=args.subdirs, dry_run=args.dry_run) |
| 172 rebaseliner.RebaselineAll() | 200 rebaseliner.RebaselineAll() |
| OLD | NEW |