blob: 9a3578d04cbfe85d2c3f9feca1512cfc046da668 [file] [log] [blame]
senorblanco@chromium.org782f3b42012-10-29 18:06:26 +00001#!/usr/bin/python
2
3'''
4Copyright 2012 Google Inc.
5
6Use of this source code is governed by a BSD-style license that can be
7found in the LICENSE file.
8'''
9
10'''
senorblanco@chromium.org123a0b52012-11-29 21:50:34 +000011Rebaselines the given GM tests, on all bots and all configurations.
12Must be run from the gm-expected directory. If run from a git or SVN
13checkout, the files will be added to the staging area for commit.
senorblanco@chromium.org782f3b42012-10-29 18:06:26 +000014'''
15
epoger@google.com9166bf52013-05-30 15:46:19 +000016import argparse
epoger@google.comec3397b2013-05-29 17:09:43 +000017import os
18import subprocess
19import sys
20import tempfile
senorblanco@chromium.org782f3b42012-10-29 18:06:26 +000021
epoger@google.comec3397b2013-05-29 17:09:43 +000022# Mapping of gm-expectations subdir (under
23# https://skia.googlecode.com/svn/gm-expected/ )
24# to builder name (see list at http://108.170.217.252:10117/builders )
epoger@google.com9166bf52013-05-30 15:46:19 +000025SUBDIR_MAPPING = {
epoger@google.comec3397b2013-05-29 17:09:43 +000026 'base-shuttle-win7-intel-float':
27 'Test-Win7-ShuttleA-HD2000-x86-Release',
28 'base-shuttle-win7-intel-angle':
29 'Test-Win7-ShuttleA-HD2000-x86-Release-ANGLE',
30 'base-shuttle-win7-intel-directwrite':
31 'Test-Win7-ShuttleA-HD2000-x86-Release-DirectWrite',
32 'base-shuttle_ubuntu12_ati5770':
33 'Test-Ubuntu12-ShuttleA-ATI5770-x86_64-Release',
34 'base-macmini':
35 'Test-Mac10.6-MacMini4.1-GeForce320M-x86-Release',
36 'base-macmini-lion-float':
37 'Test-Mac10.7-MacMini4.1-GeForce320M-x86-Release',
38 'base-android-galaxy-nexus':
39 'Test-Android-GalaxyNexus-SGX540-Arm7-Debug',
40 'base-android-nexus-7':
41 'Test-Android-Nexus7-Tegra3-Arm7-Release',
42 'base-android-nexus-s':
43 'Test-Android-NexusS-SGX540-Arm7-Release',
44 'base-android-xoom':
45 'Test-Android-Xoom-Tegra2-Arm7-Release',
46 'base-android-nexus-10':
47 'Test-Android-Nexus10-MaliT604-Arm7-Release',
48}
49
epoger@google.com9166bf52013-05-30 15:46:19 +000050
51class Rebaseliner(object):
52
53 # params:
54 # tests: list of tests to rebaseline
55 # configs: which configs to run for each test
56 # subdirs: which platform subdirectories to rebaseline; if an empty list,
57 # rebaseline all platform subdirectories
58 # dry_run: if True, instead of actually downloading files or adding
59 # files to checkout, display a list of operations that
60 # we would normally perform
61 def __init__(self, tests, configs=[], subdirs=[], dry_run=False):
62 if not tests:
63 raise Exception('at least one test must be specified')
64 self._tests = tests
65 self._configs = configs
66 if not subdirs:
67 self._subdirs = sorted(SUBDIR_MAPPING.keys())
68 else:
69 self._subdirs = subdirs
70 self._dry_run = dry_run
71 self._is_svn_checkout = (
72 os.path.exists('.svn') or
73 os.path.exists(os.path.join(os.pardir, '.svn')))
74 self._is_git_checkout = (
75 os.path.exists('.git') or
76 os.path.exists(os.path.join(os.pardir, '.git')))
77
78 # Execute subprocess.call(), unless dry_run is True
79 def _Call(self, cmd, stdout=None):
80 if self._dry_run:
81 print '%s' % ' '.join(cmd)
82 return 0
83 if stdout:
84 return subprocess.call(cmd, stdout=stdout)
85 else:
86 return subprocess.call(cmd)
87
88 # Rebaseline a single file.
89 def _RebaselineOneFile(self, expectations_subdir, builder_name,
90 infilename, outfilename):
91 url = ('http://skia-autogen.googlecode.com/svn/gm-actual/' +
92 expectations_subdir + '/' + builder_name + '/' +
93 expectations_subdir + '/' + infilename)
94 cmd = [ 'curl', '--fail', '--silent', url ]
95 temp = tempfile.NamedTemporaryFile()
96 ret = self._Call(cmd, stdout=temp)
97 if ret != 0:
98 print '# Couldn\'t fetch ' + url
99 return
100 cmd = [ 'cp', temp.name, outfilename ]
101 self._Call(cmd);
102 if self._is_svn_checkout:
103 cmd = [ 'svn', 'add', '--quiet', outfilename ]
104 self._Call(cmd)
105 cmd = [ 'svn', 'propset', '--quiet', 'svn:mime-type', 'image/png',
106 outfilename ];
107 self._Call(cmd)
108 elif self._is_git_checkout:
109 cmd = [ 'git', 'add', outfilename ]
110 self._Call(cmd)
111
112 # Rebaseline the given configs for a single test.
113 #
114 # params:
115 # expectations_subdir
116 # builder_name
117 # test: a single test to rebaseline
118 def _RebaselineOneTest(self, expectations_subdir, builder_name, test):
119 if self._configs:
120 configs = self._configs
121 else:
122 if (expectations_subdir == 'base-shuttle-win7-intel-angle'):
123 configs = [ 'angle', 'anglemsaa16' ]
124 else:
125 configs = [ '565', '8888', 'gpu', 'pdf', 'mesa', 'msaa16',
126 'msaa4' ]
127 print '# ' + expectations_subdir + ':'
128 for config in configs:
129 infilename = test + '_' + config + '.png'
130 print '# ' + infilename
131 outfilename = os.path.join(expectations_subdir, infilename);
132 self._RebaselineOneFile(expectations_subdir=expectations_subdir,
133 builder_name=builder_name,
134 infilename=infilename,
135 outfilename=outfilename)
136
137 # Rebaseline all platforms/tests/types we specified in the constructor.
138 def RebaselineAll(self):
139 for test in self._tests:
140 for subdir in self._subdirs:
141 if not subdir in SUBDIR_MAPPING.keys():
142 raise Exception(('unrecognized platform subdir "%s"; ' +
143 'should be one of %s') % (
144 subdir, SUBDIR_MAPPING.keys()))
145 builder_name = SUBDIR_MAPPING[subdir]
146 self._RebaselineOneTest(expectations_subdir=subdir,
147 builder_name=builder_name,
148 test=test)
epoger@google.comec3397b2013-05-29 17:09:43 +0000149
150
epoger@google.com9166bf52013-05-30 15:46:19 +0000151# main...
epoger@google.comec3397b2013-05-29 17:09:43 +0000152
epoger@google.com9166bf52013-05-30 15:46:19 +0000153parser = argparse.ArgumentParser()
154parser.add_argument('--configs', metavar='CONFIG', nargs='+',
155 help='which configurations to rebaseline, e.g. ' +
156 '"--configs 565 8888"; if unspecified, run a default ' +
157 'set of configs')
158parser.add_argument('--dry_run', action='store_true',
159 help='instead of actually downloading files or adding ' +
160 'files to checkout, display a list of operations that ' +
161 'we would normally perform')
162parser.add_argument('--subdirs', metavar='SUBDIR', nargs='+',
163 help='which platform subdirectories to rebaseline; ' +
164 'if unspecified, rebaseline all subdirs, same as ' +
165 '"--subdirs %s"' % ' '.join(sorted(SUBDIR_MAPPING.keys())))
166parser.add_argument('--tests', metavar='TEST', nargs='+', required=True,
167 help='which tests to rebaseline, e.g. ' +
168 '"--tests aaclip bigmatrix"')
169args = parser.parse_args()
170rebaseliner = Rebaseliner(tests=args.tests, configs=args.configs,
171 subdirs=args.subdirs, dry_run=args.dry_run)
172rebaseliner.RebaselineAll()