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 | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 16 | import argparse |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 17 | import os |
| 18 | import subprocess |
| 19 | import sys |
senorblanco@chromium.org | 782f3b4 | 2012-10-29 18:06:26 +0000 | [diff] [blame] | 20 | |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 21 | # Mapping of gm-expectations subdir (under |
| 22 | # https://skia.googlecode.com/svn/gm-expected/ ) |
| 23 | # 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] | 24 | SUBDIR_MAPPING = { |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 25 | 'base-shuttle-win7-intel-float': |
| 26 | 'Test-Win7-ShuttleA-HD2000-x86-Release', |
| 27 | 'base-shuttle-win7-intel-angle': |
| 28 | 'Test-Win7-ShuttleA-HD2000-x86-Release-ANGLE', |
| 29 | 'base-shuttle-win7-intel-directwrite': |
| 30 | 'Test-Win7-ShuttleA-HD2000-x86-Release-DirectWrite', |
| 31 | 'base-shuttle_ubuntu12_ati5770': |
| 32 | 'Test-Ubuntu12-ShuttleA-ATI5770-x86_64-Release', |
| 33 | 'base-macmini': |
| 34 | 'Test-Mac10.6-MacMini4.1-GeForce320M-x86-Release', |
| 35 | 'base-macmini-lion-float': |
| 36 | 'Test-Mac10.7-MacMini4.1-GeForce320M-x86-Release', |
| 37 | 'base-android-galaxy-nexus': |
| 38 | 'Test-Android-GalaxyNexus-SGX540-Arm7-Debug', |
| 39 | 'base-android-nexus-7': |
| 40 | 'Test-Android-Nexus7-Tegra3-Arm7-Release', |
| 41 | 'base-android-nexus-s': |
| 42 | 'Test-Android-NexusS-SGX540-Arm7-Release', |
| 43 | 'base-android-xoom': |
| 44 | 'Test-Android-Xoom-Tegra2-Arm7-Release', |
| 45 | 'base-android-nexus-10': |
| 46 | 'Test-Android-Nexus10-MaliT604-Arm7-Release', |
| 47 | } |
| 48 | |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 49 | |
epoger@google.com | db29a31 | 2013-06-04 14:58:47 +0000 | [diff] [blame^] | 50 | class CommandFailedException(Exception): |
| 51 | pass |
| 52 | |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 53 | class Rebaseliner(object): |
| 54 | |
| 55 | # params: |
| 56 | # tests: list of tests to rebaseline |
| 57 | # configs: which configs to run for each test |
| 58 | # subdirs: which platform subdirectories to rebaseline; if an empty list, |
| 59 | # rebaseline all platform subdirectories |
| 60 | # dry_run: if True, instead of actually downloading files or adding |
| 61 | # files to checkout, display a list of operations that |
| 62 | # we would normally perform |
| 63 | def __init__(self, tests, configs=[], subdirs=[], dry_run=False): |
| 64 | if not tests: |
| 65 | raise Exception('at least one test must be specified') |
| 66 | self._tests = tests |
| 67 | self._configs = configs |
| 68 | if not subdirs: |
| 69 | self._subdirs = sorted(SUBDIR_MAPPING.keys()) |
| 70 | else: |
| 71 | self._subdirs = subdirs |
| 72 | self._dry_run = dry_run |
| 73 | self._is_svn_checkout = ( |
| 74 | os.path.exists('.svn') or |
| 75 | os.path.exists(os.path.join(os.pardir, '.svn'))) |
| 76 | self._is_git_checkout = ( |
| 77 | os.path.exists('.git') or |
| 78 | os.path.exists(os.path.join(os.pardir, '.git'))) |
| 79 | |
epoger@google.com | db29a31 | 2013-06-04 14:58:47 +0000 | [diff] [blame^] | 80 | # If dry_run is False, execute subprocess.call(cmd). |
| 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): |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 84 | if self._dry_run: |
| 85 | print '%s' % ' '.join(cmd) |
epoger@google.com | db29a31 | 2013-06-04 14:58:47 +0000 | [diff] [blame^] | 86 | return |
| 87 | if subprocess.call(cmd) != 0: |
| 88 | raise CommandFailedException('error running command: ' + |
| 89 | ' '.join(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 ]) |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 103 | |
| 104 | # Rebaseline a single file. |
| 105 | def _RebaselineOneFile(self, expectations_subdir, builder_name, |
| 106 | infilename, outfilename): |
| 107 | url = ('http://skia-autogen.googlecode.com/svn/gm-actual/' + |
| 108 | expectations_subdir + '/' + builder_name + '/' + |
| 109 | expectations_subdir + '/' + infilename) |
epoger@google.com | db29a31 | 2013-06-04 14:58:47 +0000 | [diff] [blame^] | 110 | |
| 111 | # Try to download this file, but if that fails, keep going... |
| 112 | # |
| 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: |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 126 | print '# Couldn\'t fetch ' + url |
| 127 | return |
epoger@google.com | db29a31 | 2013-06-04 14:58:47 +0000 | [diff] [blame^] | 128 | |
| 129 | # Add this file to version control (if it isn't already). |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 130 | if self._is_svn_checkout: |
| 131 | cmd = [ 'svn', 'add', '--quiet', outfilename ] |
| 132 | self._Call(cmd) |
| 133 | cmd = [ 'svn', 'propset', '--quiet', 'svn:mime-type', 'image/png', |
| 134 | outfilename ]; |
| 135 | self._Call(cmd) |
| 136 | elif self._is_git_checkout: |
| 137 | cmd = [ 'git', 'add', outfilename ] |
| 138 | self._Call(cmd) |
| 139 | |
| 140 | # Rebaseline the given configs for a single test. |
| 141 | # |
| 142 | # params: |
| 143 | # expectations_subdir |
| 144 | # builder_name |
| 145 | # test: a single test to rebaseline |
| 146 | def _RebaselineOneTest(self, expectations_subdir, builder_name, test): |
| 147 | if self._configs: |
| 148 | configs = self._configs |
| 149 | else: |
| 150 | if (expectations_subdir == 'base-shuttle-win7-intel-angle'): |
| 151 | configs = [ 'angle', 'anglemsaa16' ] |
| 152 | else: |
| 153 | configs = [ '565', '8888', 'gpu', 'pdf', 'mesa', 'msaa16', |
| 154 | 'msaa4' ] |
| 155 | print '# ' + expectations_subdir + ':' |
| 156 | for config in configs: |
| 157 | infilename = test + '_' + config + '.png' |
| 158 | print '# ' + infilename |
| 159 | outfilename = os.path.join(expectations_subdir, infilename); |
| 160 | self._RebaselineOneFile(expectations_subdir=expectations_subdir, |
| 161 | builder_name=builder_name, |
| 162 | infilename=infilename, |
| 163 | outfilename=outfilename) |
| 164 | |
| 165 | # Rebaseline all platforms/tests/types we specified in the constructor. |
| 166 | def RebaselineAll(self): |
| 167 | for test in self._tests: |
| 168 | for subdir in self._subdirs: |
| 169 | if not subdir in SUBDIR_MAPPING.keys(): |
| 170 | raise Exception(('unrecognized platform subdir "%s"; ' + |
| 171 | 'should be one of %s') % ( |
| 172 | subdir, SUBDIR_MAPPING.keys())) |
| 173 | builder_name = SUBDIR_MAPPING[subdir] |
| 174 | self._RebaselineOneTest(expectations_subdir=subdir, |
| 175 | builder_name=builder_name, |
| 176 | test=test) |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 177 | |
| 178 | |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 179 | # main... |
epoger@google.com | ec3397b | 2013-05-29 17:09:43 +0000 | [diff] [blame] | 180 | |
epoger@google.com | 9166bf5 | 2013-05-30 15:46:19 +0000 | [diff] [blame] | 181 | parser = argparse.ArgumentParser() |
| 182 | parser.add_argument('--configs', metavar='CONFIG', nargs='+', |
| 183 | help='which configurations to rebaseline, e.g. ' + |
| 184 | '"--configs 565 8888"; if unspecified, run a default ' + |
| 185 | 'set of configs') |
| 186 | parser.add_argument('--dry_run', action='store_true', |
| 187 | help='instead of actually downloading files or adding ' + |
| 188 | 'files to checkout, display a list of operations that ' + |
| 189 | 'we would normally perform') |
| 190 | parser.add_argument('--subdirs', metavar='SUBDIR', nargs='+', |
| 191 | help='which platform subdirectories to rebaseline; ' + |
| 192 | 'if unspecified, rebaseline all subdirs, same as ' + |
| 193 | '"--subdirs %s"' % ' '.join(sorted(SUBDIR_MAPPING.keys()))) |
| 194 | parser.add_argument('--tests', metavar='TEST', nargs='+', required=True, |
| 195 | help='which tests to rebaseline, e.g. ' + |
| 196 | '"--tests aaclip bigmatrix"') |
| 197 | args = parser.parse_args() |
| 198 | rebaseliner = Rebaseliner(tests=args.tests, configs=args.configs, |
| 199 | subdirs=args.subdirs, dry_run=args.dry_run) |
| 200 | rebaseliner.RebaselineAll() |