blob: d4edf5034c195e800688ab08617d39be1fb1d220 [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.
senorblanco@chromium.org782f3b42012-10-29 18:06:26 +000012'''
13
epoger@google.com99ba65a2013-06-05 15:43:37 +000014# System-level imports
epoger@google.com9166bf52013-05-30 15:46:19 +000015import argparse
epoger@google.comfd040112013-08-20 16:21:55 +000016import json
epoger@google.comec3397b2013-05-29 17:09:43 +000017import os
epoger@google.come78d2072013-06-12 17:44:14 +000018import re
epoger@google.com27e1c002013-07-24 15:38:39 +000019import subprocess
epoger@google.comec3397b2013-05-29 17:09:43 +000020import sys
epoger@google.com99ba65a2013-06-05 15:43:37 +000021import urllib2
22
23# Imports from within Skia
24#
epoger@google.comdad53102013-06-12 14:25:30 +000025# We need to add the 'gm' directory, so that we can import gm_json.py within
26# that directory. That script allows us to parse the actual-results.json file
27# written out by the GM tool.
28# Make sure that the 'gm' dir is in the PYTHONPATH, but add it at the *end*
29# so any dirs that are already in the PYTHONPATH will be preferred.
30#
31# This assumes that the 'gm' directory has been checked out as a sibling of
32# the 'tools' directory containing this script, which will be the case if
33# 'trunk' was checked out as a single unit.
epoger@google.com99ba65a2013-06-05 15:43:37 +000034GM_DIRECTORY = os.path.realpath(
35 os.path.join(os.path.dirname(os.path.dirname(__file__)), 'gm'))
36if GM_DIRECTORY not in sys.path:
epoger@google.com2a192a82013-08-02 20:54:46 +000037 sys.path.append(GM_DIRECTORY)
epoger@google.com99ba65a2013-06-05 15:43:37 +000038import gm_json
39
epoger@google.com44f165f2013-08-24 20:45:31 +000040# TODO(epoger): In the long run, we want to build this list automatically,
41# but for now we hard-code it until we can properly address
42# https://code.google.com/p/skia/issues/detail?id=1544
43# ('live query of builder list makes rebaseline.py slow to start up')
44TEST_BUILDERS = [
45 'Test-Android-GalaxyNexus-SGX540-Arm7-Debug',
46 'Test-Android-GalaxyNexus-SGX540-Arm7-Release',
47 'Test-Android-IntelRhb-SGX544-x86-Debug',
48 'Test-Android-IntelRhb-SGX544-x86-Release',
49 'Test-Android-Nexus10-MaliT604-Arm7-Debug',
50 'Test-Android-Nexus10-MaliT604-Arm7-Release',
51 'Test-Android-Nexus4-Adreno320-Arm7-Debug',
52 'Test-Android-Nexus4-Adreno320-Arm7-Release',
53 'Test-Android-Nexus7-Tegra3-Arm7-Debug',
54 'Test-Android-Nexus7-Tegra3-Arm7-Release',
55 'Test-Android-NexusS-SGX540-Arm7-Debug',
56 'Test-Android-NexusS-SGX540-Arm7-Release',
57 'Test-Android-Xoom-Tegra2-Arm7-Debug',
58 'Test-Android-Xoom-Tegra2-Arm7-Release',
59 'Test-ChromeOS-Alex-GMA3150-x86-Debug',
60 'Test-ChromeOS-Alex-GMA3150-x86-Release',
61 'Test-ChromeOS-Daisy-MaliT604-Arm7-Debug',
62 'Test-ChromeOS-Daisy-MaliT604-Arm7-Release',
63 'Test-ChromeOS-Link-HD4000-x86_64-Debug',
64 'Test-ChromeOS-Link-HD4000-x86_64-Release',
65 'Test-Mac10.6-MacMini4.1-GeForce320M-x86-Debug',
66 'Test-Mac10.6-MacMini4.1-GeForce320M-x86-Release',
67 'Test-Mac10.6-MacMini4.1-GeForce320M-x86_64-Debug',
68 'Test-Mac10.6-MacMini4.1-GeForce320M-x86_64-Release',
69 'Test-Mac10.7-MacMini4.1-GeForce320M-x86-Debug',
70 'Test-Mac10.7-MacMini4.1-GeForce320M-x86-Release',
71 'Test-Mac10.7-MacMini4.1-GeForce320M-x86_64-Debug',
72 'Test-Mac10.7-MacMini4.1-GeForce320M-x86_64-Release',
73 'Test-Mac10.8-MacMini4.1-GeForce320M-x86-Debug',
74 'Test-Mac10.8-MacMini4.1-GeForce320M-x86-Release',
75 'Test-Mac10.8-MacMini4.1-GeForce320M-x86_64-Debug',
76 'Test-Mac10.8-MacMini4.1-GeForce320M-x86_64-Release',
77 'Test-Ubuntu12-ShuttleA-ATI5770-x86-Debug',
78 'Test-Ubuntu12-ShuttleA-ATI5770-x86-Release',
79 'Test-Ubuntu12-ShuttleA-ATI5770-x86_64-Debug',
80 'Test-Ubuntu12-ShuttleA-ATI5770-x86_64-Release',
81 'Test-Ubuntu12-ShuttleA-HD2000-x86_64-Release-Valgrind',
82 'Test-Ubuntu12-ShuttleA-NoGPU-x86_64-Debug',
83 'Test-Ubuntu13-ShuttleA-HD2000-x86_64-Debug-ASAN',
84 'Test-Win7-ShuttleA-HD2000-x86-Debug',
85 'Test-Win7-ShuttleA-HD2000-x86-Debug-ANGLE',
86 'Test-Win7-ShuttleA-HD2000-x86-Debug-DirectWrite',
87 'Test-Win7-ShuttleA-HD2000-x86-Release',
88 'Test-Win7-ShuttleA-HD2000-x86-Release-ANGLE',
89 'Test-Win7-ShuttleA-HD2000-x86-Release-DirectWrite',
90 'Test-Win7-ShuttleA-HD2000-x86_64-Debug',
91 'Test-Win7-ShuttleA-HD2000-x86_64-Release',
92]
epoger@google.com9166bf52013-05-30 15:46:19 +000093
epoger@google.com66ba9f92013-07-11 19:20:30 +000094class _InternalException(Exception):
epoger@google.com2a192a82013-08-02 20:54:46 +000095 pass
epoger@google.comdb29a312013-06-04 14:58:47 +000096
epoger@google.comffcbdbf2013-07-16 17:35:39 +000097class ExceptionHandler(object):
epoger@google.com93acfd22013-09-03 18:27:19 +000098 """ Object that handles exceptions, either raising them immediately or
99 collecting them to display later on."""
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000100
epoger@google.com2a192a82013-08-02 20:54:46 +0000101 # params:
epoger@google.com2a192a82013-08-02 20:54:46 +0000102 def __init__(self, keep_going_on_failure=False):
epoger@google.com93acfd22013-09-03 18:27:19 +0000103 """
104 params:
105 keep_going_on_failure: if False, report failures and quit right away;
106 if True, collect failures until
107 ReportAllFailures() is called
108 """
epoger@google.com2a192a82013-08-02 20:54:46 +0000109 self._keep_going_on_failure = keep_going_on_failure
110 self._failures_encountered = []
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000111
epoger@google.com93acfd22013-09-03 18:27:19 +0000112 def RaiseExceptionOrContinue(self):
113 """ We have encountered an exception; either collect the info and keep
114 going, or exit the program right away."""
115 # Get traceback information about the most recently raised exception.
116 exc_info = sys.exc_info()
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000117
epoger@google.com2a192a82013-08-02 20:54:46 +0000118 if self._keep_going_on_failure:
epoger@google.com93acfd22013-09-03 18:27:19 +0000119 print >> sys.stderr, ('WARNING: swallowing exception %s' %
120 repr(exc_info[1]))
121 self._failures_encountered.append(exc_info)
epoger@google.com2a192a82013-08-02 20:54:46 +0000122 else:
epoger@google.com2a192a82013-08-02 20:54:46 +0000123 print >> sys.stderr, (
epoger@google.com80f9cf12013-09-06 17:26:09 +0000124 '\nHalting at first exception.\n' +
125 'Please file a bug to epoger@google.com at ' +
126 'https://code.google.com/p/skia/issues/entry, containing the ' +
127 'command you ran and the following stack trace.\n\n' +
128 'Afterwards, you can re-run with the --keep-going-on-failure ' +
129 'option set.\n')
epoger@google.com93acfd22013-09-03 18:27:19 +0000130 raise exc_info[1], None, exc_info[2]
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000131
epoger@google.com2a192a82013-08-02 20:54:46 +0000132 def ReportAllFailures(self):
133 if self._failures_encountered:
134 print >> sys.stderr, ('Encountered %d failures (see above).' %
135 len(self._failures_encountered))
epoger@google.com93acfd22013-09-03 18:27:19 +0000136 sys.exit(1)
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000137
138
epoger@google.com99a8ec92013-06-19 18:56:59 +0000139# Object that rebaselines a JSON expectations file (not individual image files).
epoger@google.com99a8ec92013-06-19 18:56:59 +0000140class JsonRebaseliner(object):
epoger@google.com9166bf52013-05-30 15:46:19 +0000141
epoger@google.com2a192a82013-08-02 20:54:46 +0000142 # params:
143 # expectations_root: root directory of all expectations JSON files
144 # expectations_input_filename: filename (under expectations_root) of JSON
145 # expectations file to read; typically
146 # "expected-results.json"
147 # expectations_output_filename: filename (under expectations_root) to
148 # which updated expectations should be
149 # written; typically the same as
150 # expectations_input_filename, to overwrite
151 # the old content
152 # actuals_base_url: base URL from which to read actual-result JSON files
153 # actuals_filename: filename (under actuals_base_url) from which to read a
154 # summary of results; typically "actual-results.json"
155 # exception_handler: reference to rebaseline.ExceptionHandler object
156 # tests: list of tests to rebaseline, or None if we should rebaseline
157 # whatever files the JSON results summary file tells us to
158 # configs: which configs to run for each test, or None if we should
159 # rebaseline whatever configs the JSON results summary file tells
160 # us to
161 # add_new: if True, add expectations for tests which don't have any yet
epoger@google.com06e626d2013-09-03 17:32:15 +0000162 # bugs: optional list of bug numbers which pertain to these expectations
163 # notes: free-form text notes to add to all updated expectations
164 # mark_unreviewed: if True, mark these expectations as NOT having been
165 # reviewed by a human; otherwise, leave that field blank.
166 # Currently, there is no way to make this script mark
167 # expectations as reviewed-by-human=True.
168 # TODO(epoger): Add that capability to a review tool.
epoger@google.com2a192a82013-08-02 20:54:46 +0000169 def __init__(self, expectations_root, expectations_input_filename,
170 expectations_output_filename, actuals_base_url,
171 actuals_filename, exception_handler,
epoger@google.com06e626d2013-09-03 17:32:15 +0000172 tests=None, configs=None, add_new=False, bugs=None, notes=None,
173 mark_unreviewed=None):
epoger@google.com2a192a82013-08-02 20:54:46 +0000174 self._expectations_root = expectations_root
175 self._expectations_input_filename = expectations_input_filename
176 self._expectations_output_filename = expectations_output_filename
177 self._tests = tests
178 self._configs = configs
179 self._actuals_base_url = actuals_base_url
180 self._actuals_filename = actuals_filename
181 self._exception_handler = exception_handler
182 self._add_new = add_new
epoger@google.com06e626d2013-09-03 17:32:15 +0000183 self._bugs = bugs
184 self._notes = notes
185 self._mark_unreviewed = mark_unreviewed
epoger@google.com2a192a82013-08-02 20:54:46 +0000186 self._image_filename_re = re.compile(gm_json.IMAGE_FILENAME_PATTERN)
187 self._using_svn = os.path.isdir(os.path.join(expectations_root, '.svn'))
epoger@google.com27e1c002013-07-24 15:38:39 +0000188
epoger@google.com2a192a82013-08-02 20:54:46 +0000189 # Executes subprocess.call(cmd).
190 # Raises an Exception if the command fails.
191 def _Call(self, cmd):
192 if subprocess.call(cmd) != 0:
193 raise _InternalException('error running command: ' + ' '.join(cmd))
epoger@google.com9166bf52013-05-30 15:46:19 +0000194
epoger@google.com2a192a82013-08-02 20:54:46 +0000195 # Returns the full contents of filepath, as a single string.
196 # If filepath looks like a URL, try to read it that way instead of as
197 # a path on local storage.
198 #
199 # Raises _InternalException if there is a problem.
200 def _GetFileContents(self, filepath):
201 if filepath.startswith('http:') or filepath.startswith('https:'):
202 try:
203 return urllib2.urlopen(filepath).read()
204 except urllib2.HTTPError as e:
205 raise _InternalException('unable to read URL %s: %s' % (
206 filepath, e))
207 else:
208 return open(filepath, 'r').read()
epoger@google.com99ba65a2013-06-05 15:43:37 +0000209
epoger@google.com2a192a82013-08-02 20:54:46 +0000210 # Returns a dictionary of actual results from actual-results.json file.
211 #
212 # The dictionary returned has this format:
213 # {
214 # u'imageblur_565.png': [u'bitmap-64bitMD5', 3359963596899141322],
215 # u'imageblur_8888.png': [u'bitmap-64bitMD5', 4217923806027861152],
216 # u'shadertext3_8888.png': [u'bitmap-64bitMD5', 3713708307125704716]
217 # }
218 #
219 # If the JSON actual result summary file cannot be loaded, logs a warning
220 # message and returns None.
221 # If the JSON actual result summary file can be loaded, but we have
222 # trouble parsing it, raises an Exception.
223 #
224 # params:
225 # json_url: URL pointing to a JSON actual result summary file
226 # sections: a list of section names to include in the results, e.g.
227 # [gm_json.JSONKEY_ACTUALRESULTS_FAILED,
228 # gm_json.JSONKEY_ACTUALRESULTS_NOCOMPARISON] ;
229 # if None, then include ALL sections.
230 def _GetActualResults(self, json_url, sections=None):
231 try:
232 json_contents = self._GetFileContents(json_url)
233 except _InternalException:
234 print >> sys.stderr, (
235 'could not read json_url %s ; skipping this platform.' %
236 json_url)
237 return None
238 json_dict = gm_json.LoadFromString(json_contents)
239 results_to_return = {}
240 actual_results = json_dict[gm_json.JSONKEY_ACTUALRESULTS]
241 if not sections:
242 sections = actual_results.keys()
243 for section in sections:
244 section_results = actual_results[section]
245 if section_results:
246 results_to_return.update(section_results)
247 return results_to_return
epoger@google.come78d2072013-06-12 17:44:14 +0000248
epoger@google.com2a192a82013-08-02 20:54:46 +0000249 # Rebaseline all tests/types we specified in the constructor,
epoger@google.comfd040112013-08-20 16:21:55 +0000250 # within this builder's subdirectory in expectations/gm .
epoger@google.com2a192a82013-08-02 20:54:46 +0000251 #
252 # params:
epoger@google.com2a192a82013-08-02 20:54:46 +0000253 # builder : e.g. 'Test-Win7-ShuttleA-HD2000-x86-Release'
epoger@google.comfd040112013-08-20 16:21:55 +0000254 def RebaselineSubdir(self, builder):
epoger@google.com2a192a82013-08-02 20:54:46 +0000255 # Read in the actual result summary, and extract all the tests whose
256 # results we need to update.
257 actuals_url = '/'.join([self._actuals_base_url,
epoger@google.comfd040112013-08-20 16:21:55 +0000258 builder, self._actuals_filename])
epoger@google.com06e626d2013-09-03 17:32:15 +0000259 # Only update results for tests that are currently failing.
260 # We don't want to rewrite results for tests that are already succeeding,
261 # because we don't want to add annotation fields (such as
262 # JSONKEY_EXPECTEDRESULTS_BUGS) except for tests whose expectations we
263 # are actually modifying.
epoger@google.com7f5f6e62013-09-05 17:19:37 +0000264 sections = [gm_json.JSONKEY_ACTUALRESULTS_FAILED]
epoger@google.com2a192a82013-08-02 20:54:46 +0000265 if self._add_new:
266 sections.append(gm_json.JSONKEY_ACTUALRESULTS_NOCOMPARISON)
267 results_to_update = self._GetActualResults(json_url=actuals_url,
268 sections=sections)
epoger@google.come78d2072013-06-12 17:44:14 +0000269
epoger@google.com2a192a82013-08-02 20:54:46 +0000270 # Read in current expectations.
271 expectations_input_filepath = os.path.join(
epoger@google.comfd040112013-08-20 16:21:55 +0000272 self._expectations_root, builder, self._expectations_input_filename)
epoger@google.com2a192a82013-08-02 20:54:46 +0000273 expectations_dict = gm_json.LoadFromFile(expectations_input_filepath)
epoger@google.com93acfd22013-09-03 18:27:19 +0000274 expected_results = expectations_dict.get(gm_json.JSONKEY_EXPECTEDRESULTS)
275 if not expected_results:
276 expected_results = {}
277 expectations_dict[gm_json.JSONKEY_EXPECTEDRESULTS] = expected_results
epoger@google.coma783f2b2013-07-08 17:51:58 +0000278
epoger@google.com2a192a82013-08-02 20:54:46 +0000279 # Update the expectations in memory, skipping any tests/configs that
280 # the caller asked to exclude.
281 skipped_images = []
282 if results_to_update:
283 for (image_name, image_results) in results_to_update.iteritems():
284 (test, config) = self._image_filename_re.match(image_name).groups()
285 if self._tests:
286 if test not in self._tests:
287 skipped_images.append(image_name)
288 continue
289 if self._configs:
290 if config not in self._configs:
291 skipped_images.append(image_name)
292 continue
293 if not expected_results.get(image_name):
294 expected_results[image_name] = {}
epoger@google.com06e626d2013-09-03 17:32:15 +0000295 expected_results[image_name]\
296 [gm_json.JSONKEY_EXPECTEDRESULTS_ALLOWEDDIGESTS]\
297 = [image_results]
298 if self._mark_unreviewed:
299 expected_results[image_name]\
300 [gm_json.JSONKEY_EXPECTEDRESULTS_REVIEWED]\
301 = False
302 if self._bugs:
303 expected_results[image_name]\
304 [gm_json.JSONKEY_EXPECTEDRESULTS_BUGS]\
305 = self._bugs
306 if self._notes:
307 expected_results[image_name]\
308 [gm_json.JSONKEY_EXPECTEDRESULTS_NOTES]\
309 = self._notes
epoger@google.coma783f2b2013-07-08 17:51:58 +0000310
epoger@google.com2a192a82013-08-02 20:54:46 +0000311 # Write out updated expectations.
312 expectations_output_filepath = os.path.join(
epoger@google.comfd040112013-08-20 16:21:55 +0000313 self._expectations_root, builder, self._expectations_output_filename)
epoger@google.com2a192a82013-08-02 20:54:46 +0000314 gm_json.WriteToFile(expectations_dict, expectations_output_filepath)
epoger@google.coma783f2b2013-07-08 17:51:58 +0000315
epoger@google.com2a192a82013-08-02 20:54:46 +0000316 # Mark the JSON file as plaintext, so text-style diffs can be applied.
317 # Fixes https://code.google.com/p/skia/issues/detail?id=1442
318 if self._using_svn:
319 self._Call(['svn', 'propset', '--quiet', 'svn:mime-type',
320 'text/x-json', expectations_output_filepath])
epoger@google.comec3397b2013-05-29 17:09:43 +0000321
epoger@google.com9166bf52013-05-30 15:46:19 +0000322# main...
epoger@google.comec3397b2013-05-29 17:09:43 +0000323
epoger@google.com9166bf52013-05-30 15:46:19 +0000324parser = argparse.ArgumentParser()
epoger@google.coma783f2b2013-07-08 17:51:58 +0000325parser.add_argument('--actuals-base-url',
epoger@google.com06e626d2013-09-03 17:32:15 +0000326 help=('base URL from which to read files containing JSON '
327 'summaries of actual GM results; defaults to '
328 '%(default)s'),
epoger@google.coma783f2b2013-07-08 17:51:58 +0000329 default='http://skia-autogen.googlecode.com/svn/gm-actual')
330parser.add_argument('--actuals-filename',
epoger@google.com06e626d2013-09-03 17:32:15 +0000331 help=('filename (within builder-specific subdirectories '
332 'of ACTUALS_BASE_URL) to read a summary of results '
333 'from; defaults to %(default)s'),
epoger@google.coma783f2b2013-07-08 17:51:58 +0000334 default='actual-results.json')
epoger@google.comdad53102013-06-12 14:25:30 +0000335parser.add_argument('--add-new', action='store_true',
epoger@google.com06e626d2013-09-03 17:32:15 +0000336 help=('in addition to the standard behavior of '
337 'updating expectations for failing tests, add '
338 'expectations for tests which don\'t have '
339 'expectations yet.'))
340parser.add_argument('--bugs', metavar='BUG', type=int, nargs='+',
341 help=('Skia bug numbers (under '
342 'https://code.google.com/p/skia/issues/list ) which '
343 'pertain to this set of rebaselines.'))
epoger@google.comfd040112013-08-20 16:21:55 +0000344parser.add_argument('--builders', metavar='BUILDER', nargs='+',
epoger@google.com06e626d2013-09-03 17:32:15 +0000345 help=('which platforms to rebaseline; '
346 'if unspecified, rebaseline all platforms, same as '
347 '"--builders %s"' % ' '.join(sorted(TEST_BUILDERS))))
epoger@google.coma783f2b2013-07-08 17:51:58 +0000348# TODO(epoger): Add test that exercises --configs argument.
epoger@google.com9166bf52013-05-30 15:46:19 +0000349parser.add_argument('--configs', metavar='CONFIG', nargs='+',
epoger@google.com06e626d2013-09-03 17:32:15 +0000350 help=('which configurations to rebaseline, e.g. '
351 '"--configs 565 8888", as a filter over the full set '
352 'of results in ACTUALS_FILENAME; if unspecified, '
353 'rebaseline *all* configs that are available.'))
epoger@google.coma783f2b2013-07-08 17:51:58 +0000354parser.add_argument('--expectations-filename',
epoger@google.com06e626d2013-09-03 17:32:15 +0000355 help=('filename (under EXPECTATIONS_ROOT) to read '
356 'current expectations from, and to write new '
357 'expectations into (unless a separate '
358 'EXPECTATIONS_FILENAME_OUTPUT has been specified); '
359 'defaults to %(default)s'),
epoger@google.coma783f2b2013-07-08 17:51:58 +0000360 default='expected-results.json')
epoger@google.comc60e7452013-07-24 19:36:51 +0000361parser.add_argument('--expectations-filename-output',
epoger@google.com06e626d2013-09-03 17:32:15 +0000362 help=('filename (under EXPECTATIONS_ROOT) to write '
363 'updated expectations into; by default, overwrites '
364 'the input file (EXPECTATIONS_FILENAME)'),
epoger@google.comc60e7452013-07-24 19:36:51 +0000365 default='')
epoger@google.com99a8ec92013-06-19 18:56:59 +0000366parser.add_argument('--expectations-root',
epoger@google.com06e626d2013-09-03 17:32:15 +0000367 help=('root of expectations directory to update-- should '
368 'contain one or more builder subdirectories. '
369 'Defaults to %(default)s'),
epoger@google.come94a7d22013-07-23 19:37:03 +0000370 default=os.path.join('expectations', 'gm'))
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000371parser.add_argument('--keep-going-on-failure', action='store_true',
epoger@google.com06e626d2013-09-03 17:32:15 +0000372 help=('instead of halting at the first error encountered, '
373 'keep going and rebaseline as many tests as '
374 'possible, and then report the full set of errors '
375 'at the end'))
376parser.add_argument('--notes',
377 help=('free-form text notes to add to all updated '
378 'expectations'))
epoger@google.coma783f2b2013-07-08 17:51:58 +0000379# TODO(epoger): Add test that exercises --tests argument.
epoger@google.com99ba65a2013-06-05 15:43:37 +0000380parser.add_argument('--tests', metavar='TEST', nargs='+',
epoger@google.com06e626d2013-09-03 17:32:15 +0000381 help=('which tests to rebaseline, e.g. '
382 '"--tests aaclip bigmatrix", as a filter over the '
383 'full set of results in ACTUALS_FILENAME; if '
384 'unspecified, rebaseline *all* tests that are '
385 'available.'))
386parser.add_argument('--unreviewed', action='store_true',
387 help=('mark all expectations modified by this run as '
388 '"%s": False' %
389 gm_json.JSONKEY_EXPECTEDRESULTS_REVIEWED))
epoger@google.com9166bf52013-05-30 15:46:19 +0000390args = parser.parse_args()
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000391exception_handler = ExceptionHandler(
392 keep_going_on_failure=args.keep_going_on_failure)
epoger@google.comfd040112013-08-20 16:21:55 +0000393if args.builders:
394 builders = args.builders
epoger@google.com2a192a82013-08-02 20:54:46 +0000395 missing_json_is_fatal = True
epoger@google.com99a8ec92013-06-19 18:56:59 +0000396else:
epoger@google.comfd040112013-08-20 16:21:55 +0000397 builders = sorted(TEST_BUILDERS)
epoger@google.com2a192a82013-08-02 20:54:46 +0000398 missing_json_is_fatal = False
epoger@google.comfd040112013-08-20 16:21:55 +0000399for builder in builders:
400 if not builder in TEST_BUILDERS:
401 raise Exception(('unrecognized builder "%s"; ' +
epoger@google.com2a192a82013-08-02 20:54:46 +0000402 'should be one of %s') % (
epoger@google.comfd040112013-08-20 16:21:55 +0000403 builder, TEST_BUILDERS))
epoger@google.com99a8ec92013-06-19 18:56:59 +0000404
epoger@google.comfd040112013-08-20 16:21:55 +0000405 expectations_json_file = os.path.join(args.expectations_root, builder,
epoger@google.com2a192a82013-08-02 20:54:46 +0000406 args.expectations_filename)
407 if os.path.isfile(expectations_json_file):
408 rebaseliner = JsonRebaseliner(
409 expectations_root=args.expectations_root,
410 expectations_input_filename=args.expectations_filename,
411 expectations_output_filename=(args.expectations_filename_output or
412 args.expectations_filename),
413 tests=args.tests, configs=args.configs,
414 actuals_base_url=args.actuals_base_url,
415 actuals_filename=args.actuals_filename,
416 exception_handler=exception_handler,
epoger@google.com06e626d2013-09-03 17:32:15 +0000417 add_new=args.add_new, bugs=args.bugs, notes=args.notes,
418 mark_unreviewed=args.unreviewed)
epoger@google.com3e7399f2013-07-10 17:23:47 +0000419 try:
epoger@google.comfd040112013-08-20 16:21:55 +0000420 rebaseliner.RebaselineSubdir(builder=builder)
epoger@google.com93acfd22013-09-03 18:27:19 +0000421 except:
422 exception_handler.RaiseExceptionOrContinue()
epoger@google.com2a192a82013-08-02 20:54:46 +0000423 else:
epoger@google.com93acfd22013-09-03 18:27:19 +0000424 try:
425 raise _InternalException('expectations_json_file %s not found' %
426 expectations_json_file)
427 except:
428 exception_handler.RaiseExceptionOrContinue()
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000429
430exception_handler.ReportAllFailures()