rebaseline.py: use argparse command-line flags for more flexibility

--tests is the only mandatory argument.

If you used to run this:
rebaseline.py aaclip bigmatrix

Run this instead:
rebaseline.py --tests aaclip bigmatrix

That's the only change you NEED to make.

And then, if you WANT to specify --configs, --subdirs, etc. you CAN.

R=senorblanco@chromium.org

Review URL: https://codereview.chromium.org/15675010

git-svn-id: http://skia.googlecode.com/svn/trunk@9348 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
epoger@google.com 2013-05-30 15:46:19 +00:00
parent fa2f2a48f6
commit 9166bf57d8

View File

@ -13,6 +13,7 @@ Must be run from the gm-expected directory. If run from a git or SVN
checkout, the files will be added to the staging area for commit.
'''
import argparse
import os
import subprocess
import sys
@ -21,7 +22,7 @@ import tempfile
# Mapping of gm-expectations subdir (under
# https://skia.googlecode.com/svn/gm-expected/ )
# to builder name (see list at http://108.170.217.252:10117/builders )
subdir_mapping = {
SUBDIR_MAPPING = {
'base-shuttle-win7-intel-float':
'Test-Win7-ShuttleA-HD2000-x86-Release',
'base-shuttle-win7-intel-angle':
@ -46,63 +47,126 @@ subdir_mapping = {
'Test-Android-Nexus10-MaliT604-Arm7-Release',
}
IS_SVN_CHECKOUT = (os.path.exists('.svn') or
os.path.exists(os.path.join('..', '.svn')))
IS_GIT_CHECKOUT = (os.path.exists('.git') or
os.path.exists(os.path.join('..', '.git')))
class Rebaseliner(object):
# params:
# tests: list of tests to rebaseline
# configs: which configs to run for each test
# subdirs: which platform subdirectories to rebaseline; if an empty list,
# rebaseline all platform subdirectories
# dry_run: if True, instead of actually downloading files or adding
# files to checkout, display a list of operations that
# we would normally perform
def __init__(self, tests, configs=[], subdirs=[], dry_run=False):
if not tests:
raise Exception('at least one test must be specified')
self._tests = tests
self._configs = configs
if not subdirs:
self._subdirs = sorted(SUBDIR_MAPPING.keys())
else:
self._subdirs = subdirs
self._dry_run = dry_run
self._is_svn_checkout = (
os.path.exists('.svn') or
os.path.exists(os.path.join(os.pardir, '.svn')))
self._is_git_checkout = (
os.path.exists('.git') or
os.path.exists(os.path.join(os.pardir, '.git')))
# Execute subprocess.call(), unless dry_run is True
def _Call(self, cmd, stdout=None):
if self._dry_run:
print '%s' % ' '.join(cmd)
return 0
if stdout:
return subprocess.call(cmd, stdout=stdout)
else:
return subprocess.call(cmd)
# Rebaseline a single file.
def _RebaselineOneFile(self, expectations_subdir, builder_name,
infilename, outfilename):
url = ('http://skia-autogen.googlecode.com/svn/gm-actual/' +
expectations_subdir + '/' + builder_name + '/' +
expectations_subdir + '/' + infilename)
cmd = [ 'curl', '--fail', '--silent', url ]
temp = tempfile.NamedTemporaryFile()
ret = self._Call(cmd, stdout=temp)
if ret != 0:
print '# Couldn\'t fetch ' + url
return
cmd = [ 'cp', temp.name, outfilename ]
self._Call(cmd);
if self._is_svn_checkout:
cmd = [ 'svn', 'add', '--quiet', outfilename ]
self._Call(cmd)
cmd = [ 'svn', 'propset', '--quiet', 'svn:mime-type', 'image/png',
outfilename ];
self._Call(cmd)
elif self._is_git_checkout:
cmd = [ 'git', 'add', outfilename ]
self._Call(cmd)
# Rebaseline the given configs for a single test.
#
# params:
# expectations_subdir
# builder_name
# test: a single test to rebaseline
def _RebaselineOneTest(self, expectations_subdir, builder_name, test):
if self._configs:
configs = self._configs
else:
if (expectations_subdir == 'base-shuttle-win7-intel-angle'):
configs = [ 'angle', 'anglemsaa16' ]
else:
configs = [ '565', '8888', 'gpu', 'pdf', 'mesa', 'msaa16',
'msaa4' ]
print '# ' + expectations_subdir + ':'
for config in configs:
infilename = test + '_' + config + '.png'
print '# ' + infilename
outfilename = os.path.join(expectations_subdir, infilename);
self._RebaselineOneFile(expectations_subdir=expectations_subdir,
builder_name=builder_name,
infilename=infilename,
outfilename=outfilename)
# Rebaseline all platforms/tests/types we specified in the constructor.
def RebaselineAll(self):
for test in self._tests:
for subdir in self._subdirs:
if not subdir in SUBDIR_MAPPING.keys():
raise Exception(('unrecognized platform subdir "%s"; ' +
'should be one of %s') % (
subdir, SUBDIR_MAPPING.keys()))
builder_name = SUBDIR_MAPPING[subdir]
self._RebaselineOneTest(expectations_subdir=subdir,
builder_name=builder_name,
test=test)
# Rebaseline a single file.
def RebaselineOneFile(expectations_subdir, builder_name,
infilename, outfilename):
url = ('http://skia-autogen.googlecode.com/svn/gm-actual/' +
expectations_subdir + '/' + builder_name + '/' +
expectations_subdir + '/' + infilename)
cmd = [ 'curl', '--fail', '--silent', url ]
temp = tempfile.NamedTemporaryFile()
ret = subprocess.call(cmd, stdout=temp)
if ret != 0:
print 'Couldn\'t fetch ' + url
return
cmd = [ 'cp', temp.name, outfilename ]
subprocess.call(cmd);
if IS_SVN_CHECKOUT:
cmd = [ 'svn', 'add', '--quiet', outfilename ]
subprocess.call(cmd)
cmd = [ 'svn', 'propset', '--quiet', 'svn:mime-type', 'image/png',
outfilename ];
subprocess.call(cmd)
elif IS_GIT_CHECKOUT:
cmd = [ 'git', 'add', outfilename ]
subprocess.call(cmd)
# main...
# Rebaseline all testtypes for a single test.
def RebaselineOneTest(expectations_subdir, builder_name, testname):
if (expectations_subdir == 'base-shuttle-win7-intel-angle'):
testtypes = [ 'angle', 'anglemsaa16' ]
else:
testtypes = [ '565', '8888', 'gpu', 'pdf', 'mesa', 'msaa16', 'msaa4' ]
print expectations_subdir + ':'
for testtype in testtypes:
infilename = testname + '_' + testtype + '.png'
print infilename
outfilename = os.path.join(expectations_subdir, infilename);
RebaselineOneFile(expectations_subdir=expectations_subdir,
builder_name=builder_name,
infilename=infilename,
outfilename=outfilename)
if len(sys.argv) < 2:
print ('Usage: ' + os.path.basename(sys.argv[0]) +
' <testname> [ <testname> ... ]')
exit(1)
for testname in sys.argv[1:]:
for expectations_subdir in sorted(subdir_mapping.keys()):
builder_name = subdir_mapping[expectations_subdir]
RebaselineOneTest(expectations_subdir=expectations_subdir,
builder_name=builder_name,
testname=testname)
parser = argparse.ArgumentParser()
parser.add_argument('--configs', metavar='CONFIG', nargs='+',
help='which configurations to rebaseline, e.g. ' +
'"--configs 565 8888"; if unspecified, run a default ' +
'set of configs')
parser.add_argument('--dry_run', action='store_true',
help='instead of actually downloading files or adding ' +
'files to checkout, display a list of operations that ' +
'we would normally perform')
parser.add_argument('--subdirs', metavar='SUBDIR', nargs='+',
help='which platform subdirectories to rebaseline; ' +
'if unspecified, rebaseline all subdirs, same as ' +
'"--subdirs %s"' % ' '.join(sorted(SUBDIR_MAPPING.keys())))
parser.add_argument('--tests', metavar='TEST', nargs='+', required=True,
help='which tests to rebaseline, e.g. ' +
'"--tests aaclip bigmatrix"')
args = parser.parse_args()
rebaseliner = Rebaseliner(tests=args.tests, configs=args.configs,
subdirs=args.subdirs, dry_run=args.dry_run)
rebaseliner.RebaselineAll()