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. checkout, the files will be added to the staging area for commit.
''' '''
import argparse
import os import os
import subprocess import subprocess
import sys import sys
@ -21,7 +22,7 @@ import tempfile
# Mapping of gm-expectations subdir (under # Mapping of gm-expectations subdir (under
# https://skia.googlecode.com/svn/gm-expected/ ) # https://skia.googlecode.com/svn/gm-expected/ )
# to builder name (see list at http://108.170.217.252:10117/builders ) # to builder name (see list at http://108.170.217.252:10117/builders )
subdir_mapping = { SUBDIR_MAPPING = {
'base-shuttle-win7-intel-float': 'base-shuttle-win7-intel-float':
'Test-Win7-ShuttleA-HD2000-x86-Release', 'Test-Win7-ShuttleA-HD2000-x86-Release',
'base-shuttle-win7-intel-angle': 'base-shuttle-win7-intel-angle':
@ -46,63 +47,126 @@ subdir_mapping = {
'Test-Android-Nexus10-MaliT604-Arm7-Release', 'Test-Android-Nexus10-MaliT604-Arm7-Release',
} }
IS_SVN_CHECKOUT = (os.path.exists('.svn') or
os.path.exists(os.path.join('..', '.svn'))) class Rebaseliner(object):
IS_GIT_CHECKOUT = (os.path.exists('.git') or
os.path.exists(os.path.join('..', '.git'))) # 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. # main...
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)
parser = argparse.ArgumentParser()
# Rebaseline all testtypes for a single test. parser.add_argument('--configs', metavar='CONFIG', nargs='+',
def RebaselineOneTest(expectations_subdir, builder_name, testname): help='which configurations to rebaseline, e.g. ' +
if (expectations_subdir == 'base-shuttle-win7-intel-angle'): '"--configs 565 8888"; if unspecified, run a default ' +
testtypes = [ 'angle', 'anglemsaa16' ] 'set of configs')
else: parser.add_argument('--dry_run', action='store_true',
testtypes = [ '565', '8888', 'gpu', 'pdf', 'mesa', 'msaa16', 'msaa4' ] help='instead of actually downloading files or adding ' +
print expectations_subdir + ':' 'files to checkout, display a list of operations that ' +
for testtype in testtypes: 'we would normally perform')
infilename = testname + '_' + testtype + '.png' parser.add_argument('--subdirs', metavar='SUBDIR', nargs='+',
print infilename help='which platform subdirectories to rebaseline; ' +
outfilename = os.path.join(expectations_subdir, infilename); 'if unspecified, rebaseline all subdirs, same as ' +
RebaselineOneFile(expectations_subdir=expectations_subdir, '"--subdirs %s"' % ' '.join(sorted(SUBDIR_MAPPING.keys())))
builder_name=builder_name, parser.add_argument('--tests', metavar='TEST', nargs='+', required=True,
infilename=infilename, help='which tests to rebaseline, e.g. ' +
outfilename=outfilename) '"--tests aaclip bigmatrix"')
args = parser.parse_args()
rebaseliner = Rebaseliner(tests=args.tests, configs=args.configs,
subdirs=args.subdirs, dry_run=args.dry_run)
if len(sys.argv) < 2: rebaseliner.RebaselineAll()
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)