blob: 76bbfe828ee6947310e5d2d511432212d536a139 [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
borenet@google.comb6e915d2013-09-16 18:13:13 +000094# TODO: Get this from builder_name_schema in buildbot.
95TRYBOT_SUFFIX = '-Trybot'
96
97
epoger@google.com66ba9f92013-07-11 19:20:30 +000098class _InternalException(Exception):
epoger@google.com2a192a82013-08-02 20:54:46 +000099 pass
epoger@google.comdb29a312013-06-04 14:58:47 +0000100
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000101class ExceptionHandler(object):
epoger@google.com93acfd22013-09-03 18:27:19 +0000102 """ Object that handles exceptions, either raising them immediately or
103 collecting them to display later on."""
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000104
epoger@google.com2a192a82013-08-02 20:54:46 +0000105 # params:
epoger@google.com2a192a82013-08-02 20:54:46 +0000106 def __init__(self, keep_going_on_failure=False):
epoger@google.com93acfd22013-09-03 18:27:19 +0000107 """
108 params:
109 keep_going_on_failure: if False, report failures and quit right away;
110 if True, collect failures until
111 ReportAllFailures() is called
112 """
epoger@google.com2a192a82013-08-02 20:54:46 +0000113 self._keep_going_on_failure = keep_going_on_failure
114 self._failures_encountered = []
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000115
epoger@google.com93acfd22013-09-03 18:27:19 +0000116 def RaiseExceptionOrContinue(self):
117 """ We have encountered an exception; either collect the info and keep
118 going, or exit the program right away."""
119 # Get traceback information about the most recently raised exception.
120 exc_info = sys.exc_info()
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000121
epoger@google.com2a192a82013-08-02 20:54:46 +0000122 if self._keep_going_on_failure:
epoger@google.com93acfd22013-09-03 18:27:19 +0000123 print >> sys.stderr, ('WARNING: swallowing exception %s' %
124 repr(exc_info[1]))
125 self._failures_encountered.append(exc_info)
epoger@google.com2a192a82013-08-02 20:54:46 +0000126 else:
epoger@google.com2a192a82013-08-02 20:54:46 +0000127 print >> sys.stderr, (
epoger@google.com80f9cf12013-09-06 17:26:09 +0000128 '\nHalting at first exception.\n' +
129 'Please file a bug to epoger@google.com at ' +
130 'https://code.google.com/p/skia/issues/entry, containing the ' +
131 'command you ran and the following stack trace.\n\n' +
132 'Afterwards, you can re-run with the --keep-going-on-failure ' +
133 'option set.\n')
epoger@google.com93acfd22013-09-03 18:27:19 +0000134 raise exc_info[1], None, exc_info[2]
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000135
epoger@google.com2a192a82013-08-02 20:54:46 +0000136 def ReportAllFailures(self):
137 if self._failures_encountered:
138 print >> sys.stderr, ('Encountered %d failures (see above).' %
139 len(self._failures_encountered))
epoger@google.com93acfd22013-09-03 18:27:19 +0000140 sys.exit(1)
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000141
142
epoger@google.com99a8ec92013-06-19 18:56:59 +0000143# Object that rebaselines a JSON expectations file (not individual image files).
epoger@google.com99a8ec92013-06-19 18:56:59 +0000144class JsonRebaseliner(object):
epoger@google.com9166bf52013-05-30 15:46:19 +0000145
epoger@google.com2a192a82013-08-02 20:54:46 +0000146 # params:
147 # expectations_root: root directory of all expectations JSON files
148 # expectations_input_filename: filename (under expectations_root) of JSON
149 # expectations file to read; typically
150 # "expected-results.json"
151 # expectations_output_filename: filename (under expectations_root) to
152 # which updated expectations should be
153 # written; typically the same as
154 # expectations_input_filename, to overwrite
155 # the old content
156 # actuals_base_url: base URL from which to read actual-result JSON files
157 # actuals_filename: filename (under actuals_base_url) from which to read a
158 # summary of results; typically "actual-results.json"
159 # exception_handler: reference to rebaseline.ExceptionHandler object
160 # tests: list of tests to rebaseline, or None if we should rebaseline
161 # whatever files the JSON results summary file tells us to
162 # configs: which configs to run for each test, or None if we should
163 # rebaseline whatever configs the JSON results summary file tells
164 # us to
165 # add_new: if True, add expectations for tests which don't have any yet
epoger@google.com06e626d2013-09-03 17:32:15 +0000166 # bugs: optional list of bug numbers which pertain to these expectations
167 # notes: free-form text notes to add to all updated expectations
168 # mark_unreviewed: if True, mark these expectations as NOT having been
169 # reviewed by a human; otherwise, leave that field blank.
170 # Currently, there is no way to make this script mark
171 # expectations as reviewed-by-human=True.
172 # TODO(epoger): Add that capability to a review tool.
senorblanco@chromium.orgbfc0d6b2013-09-18 19:14:43 +0000173 # mark_ignore_failure: if True, mark failures of a given test as being
174 # ignored.
scroggo@google.comd23e6832013-10-10 21:09:24 +0000175 # from_trybot: if True, read actual-result JSON files generated from a
176 # trybot run rather than a waterfall run.
epoger@google.com2a192a82013-08-02 20:54:46 +0000177 def __init__(self, expectations_root, expectations_input_filename,
178 expectations_output_filename, actuals_base_url,
179 actuals_filename, exception_handler,
epoger@google.com06e626d2013-09-03 17:32:15 +0000180 tests=None, configs=None, add_new=False, bugs=None, notes=None,
senorblanco@chromium.orgbfc0d6b2013-09-18 19:14:43 +0000181 mark_unreviewed=None, mark_ignore_failure=False,
182 from_trybot=False):
epoger@google.com2a192a82013-08-02 20:54:46 +0000183 self._expectations_root = expectations_root
184 self._expectations_input_filename = expectations_input_filename
185 self._expectations_output_filename = expectations_output_filename
186 self._tests = tests
187 self._configs = configs
188 self._actuals_base_url = actuals_base_url
189 self._actuals_filename = actuals_filename
190 self._exception_handler = exception_handler
191 self._add_new = add_new
epoger@google.com06e626d2013-09-03 17:32:15 +0000192 self._bugs = bugs
193 self._notes = notes
194 self._mark_unreviewed = mark_unreviewed
senorblanco@chromium.orgbfc0d6b2013-09-18 19:14:43 +0000195 self._mark_ignore_failure = mark_ignore_failure;
scroggo@google.comd23e6832013-10-10 21:09:24 +0000196 if self._tests or self._configs:
197 self._image_filename_re = re.compile(gm_json.IMAGE_FILENAME_PATTERN)
198 else:
199 self._image_filename_re = None
epoger@google.com2a192a82013-08-02 20:54:46 +0000200 self._using_svn = os.path.isdir(os.path.join(expectations_root, '.svn'))
borenet@google.comb6e915d2013-09-16 18:13:13 +0000201 self._from_trybot = from_trybot
epoger@google.com27e1c002013-07-24 15:38:39 +0000202
epoger@google.com2a192a82013-08-02 20:54:46 +0000203 # Executes subprocess.call(cmd).
204 # Raises an Exception if the command fails.
205 def _Call(self, cmd):
206 if subprocess.call(cmd) != 0:
207 raise _InternalException('error running command: ' + ' '.join(cmd))
epoger@google.com9166bf52013-05-30 15:46:19 +0000208
epoger@google.com2a192a82013-08-02 20:54:46 +0000209 # Returns the full contents of filepath, as a single string.
210 # If filepath looks like a URL, try to read it that way instead of as
211 # a path on local storage.
212 #
213 # Raises _InternalException if there is a problem.
214 def _GetFileContents(self, filepath):
215 if filepath.startswith('http:') or filepath.startswith('https:'):
216 try:
217 return urllib2.urlopen(filepath).read()
218 except urllib2.HTTPError as e:
219 raise _InternalException('unable to read URL %s: %s' % (
220 filepath, e))
221 else:
222 return open(filepath, 'r').read()
epoger@google.com99ba65a2013-06-05 15:43:37 +0000223
epoger@google.com2a192a82013-08-02 20:54:46 +0000224 # Returns a dictionary of actual results from actual-results.json file.
225 #
226 # The dictionary returned has this format:
227 # {
228 # u'imageblur_565.png': [u'bitmap-64bitMD5', 3359963596899141322],
229 # u'imageblur_8888.png': [u'bitmap-64bitMD5', 4217923806027861152],
230 # u'shadertext3_8888.png': [u'bitmap-64bitMD5', 3713708307125704716]
231 # }
232 #
233 # If the JSON actual result summary file cannot be loaded, logs a warning
234 # message and returns None.
235 # If the JSON actual result summary file can be loaded, but we have
236 # trouble parsing it, raises an Exception.
237 #
238 # params:
239 # json_url: URL pointing to a JSON actual result summary file
240 # sections: a list of section names to include in the results, e.g.
241 # [gm_json.JSONKEY_ACTUALRESULTS_FAILED,
242 # gm_json.JSONKEY_ACTUALRESULTS_NOCOMPARISON] ;
243 # if None, then include ALL sections.
244 def _GetActualResults(self, json_url, sections=None):
245 try:
246 json_contents = self._GetFileContents(json_url)
247 except _InternalException:
248 print >> sys.stderr, (
249 'could not read json_url %s ; skipping this platform.' %
250 json_url)
251 return None
252 json_dict = gm_json.LoadFromString(json_contents)
253 results_to_return = {}
254 actual_results = json_dict[gm_json.JSONKEY_ACTUALRESULTS]
255 if not sections:
256 sections = actual_results.keys()
257 for section in sections:
258 section_results = actual_results[section]
259 if section_results:
260 results_to_return.update(section_results)
261 return results_to_return
epoger@google.come78d2072013-06-12 17:44:14 +0000262
epoger@google.com2a192a82013-08-02 20:54:46 +0000263 # Rebaseline all tests/types we specified in the constructor,
epoger@google.comfd040112013-08-20 16:21:55 +0000264 # within this builder's subdirectory in expectations/gm .
epoger@google.com2a192a82013-08-02 20:54:46 +0000265 #
266 # params:
epoger@google.com2a192a82013-08-02 20:54:46 +0000267 # builder : e.g. 'Test-Win7-ShuttleA-HD2000-x86-Release'
epoger@google.comfd040112013-08-20 16:21:55 +0000268 def RebaselineSubdir(self, builder):
epoger@google.com2a192a82013-08-02 20:54:46 +0000269 # Read in the actual result summary, and extract all the tests whose
270 # results we need to update.
borenet@google.comb6e915d2013-09-16 18:13:13 +0000271 results_builder = str(builder)
272 if self._from_trybot:
273 results_builder = results_builder + TRYBOT_SUFFIX
274 actuals_url = '/'.join([self._actuals_base_url, results_builder,
275 self._actuals_filename])
epoger@google.com06e626d2013-09-03 17:32:15 +0000276 # Only update results for tests that are currently failing.
277 # We don't want to rewrite results for tests that are already succeeding,
278 # because we don't want to add annotation fields (such as
279 # JSONKEY_EXPECTEDRESULTS_BUGS) except for tests whose expectations we
280 # are actually modifying.
epoger@google.com7f5f6e62013-09-05 17:19:37 +0000281 sections = [gm_json.JSONKEY_ACTUALRESULTS_FAILED]
epoger@google.com2a192a82013-08-02 20:54:46 +0000282 if self._add_new:
283 sections.append(gm_json.JSONKEY_ACTUALRESULTS_NOCOMPARISON)
284 results_to_update = self._GetActualResults(json_url=actuals_url,
285 sections=sections)
epoger@google.come78d2072013-06-12 17:44:14 +0000286
epoger@google.com2a192a82013-08-02 20:54:46 +0000287 # Read in current expectations.
288 expectations_input_filepath = os.path.join(
epoger@google.comfd040112013-08-20 16:21:55 +0000289 self._expectations_root, builder, self._expectations_input_filename)
epoger@google.com2a192a82013-08-02 20:54:46 +0000290 expectations_dict = gm_json.LoadFromFile(expectations_input_filepath)
epoger@google.com93acfd22013-09-03 18:27:19 +0000291 expected_results = expectations_dict.get(gm_json.JSONKEY_EXPECTEDRESULTS)
292 if not expected_results:
293 expected_results = {}
294 expectations_dict[gm_json.JSONKEY_EXPECTEDRESULTS] = expected_results
epoger@google.coma783f2b2013-07-08 17:51:58 +0000295
epoger@google.com2a192a82013-08-02 20:54:46 +0000296 # Update the expectations in memory, skipping any tests/configs that
297 # the caller asked to exclude.
298 skipped_images = []
299 if results_to_update:
300 for (image_name, image_results) in results_to_update.iteritems():
scroggo@google.comd23e6832013-10-10 21:09:24 +0000301 if self._image_filename_re:
302 (test, config) = self._image_filename_re.match(image_name).groups()
303 if self._tests:
304 if test not in self._tests:
305 skipped_images.append(image_name)
306 continue
307 if self._configs:
308 if config not in self._configs:
309 skipped_images.append(image_name)
310 continue
epoger@google.com2a192a82013-08-02 20:54:46 +0000311 if not expected_results.get(image_name):
312 expected_results[image_name] = {}
epoger@google.com06e626d2013-09-03 17:32:15 +0000313 expected_results[image_name]\
314 [gm_json.JSONKEY_EXPECTEDRESULTS_ALLOWEDDIGESTS]\
315 = [image_results]
316 if self._mark_unreviewed:
317 expected_results[image_name]\
318 [gm_json.JSONKEY_EXPECTEDRESULTS_REVIEWED]\
319 = False
senorblanco@chromium.orgbfc0d6b2013-09-18 19:14:43 +0000320 if self._mark_ignore_failure:
321 expected_results[image_name]\
322 [gm_json.JSONKEY_EXPECTEDRESULTS_IGNOREFAILURE]\
323 = True
epoger@google.com06e626d2013-09-03 17:32:15 +0000324 if self._bugs:
325 expected_results[image_name]\
326 [gm_json.JSONKEY_EXPECTEDRESULTS_BUGS]\
327 = self._bugs
328 if self._notes:
329 expected_results[image_name]\
330 [gm_json.JSONKEY_EXPECTEDRESULTS_NOTES]\
331 = self._notes
epoger@google.coma783f2b2013-07-08 17:51:58 +0000332
epoger@google.com2a192a82013-08-02 20:54:46 +0000333 # Write out updated expectations.
334 expectations_output_filepath = os.path.join(
epoger@google.comfd040112013-08-20 16:21:55 +0000335 self._expectations_root, builder, self._expectations_output_filename)
epoger@google.com2a192a82013-08-02 20:54:46 +0000336 gm_json.WriteToFile(expectations_dict, expectations_output_filepath)
epoger@google.coma783f2b2013-07-08 17:51:58 +0000337
epoger@google.com2a192a82013-08-02 20:54:46 +0000338 # Mark the JSON file as plaintext, so text-style diffs can be applied.
339 # Fixes https://code.google.com/p/skia/issues/detail?id=1442
340 if self._using_svn:
341 self._Call(['svn', 'propset', '--quiet', 'svn:mime-type',
342 'text/x-json', expectations_output_filepath])
epoger@google.comec3397b2013-05-29 17:09:43 +0000343
epoger@google.com9166bf52013-05-30 15:46:19 +0000344# main...
epoger@google.comec3397b2013-05-29 17:09:43 +0000345
epoger@google.com6d28e8d2013-09-18 14:58:47 +0000346parser = argparse.ArgumentParser(
347 formatter_class=argparse.RawDescriptionHelpFormatter,
348 epilog='Here is the full set of builders we know about:' +
349 '\n '.join([''] + sorted(TEST_BUILDERS)))
epoger@google.coma783f2b2013-07-08 17:51:58 +0000350parser.add_argument('--actuals-base-url',
epoger@google.com06e626d2013-09-03 17:32:15 +0000351 help=('base URL from which to read files containing JSON '
352 'summaries of actual GM results; defaults to '
scroggo@google.comd23e6832013-10-10 21:09:24 +0000353 '%(default)s. To get a specific revision (useful for '
354 'trybots) replace "svn" with "svn-history/r123". '
355 'If SKIMAGE is True, defaults to ' +
356 gm_json.SKIMAGE_ACTUALS_BASE_URL),
epoger@google.coma783f2b2013-07-08 17:51:58 +0000357 default='http://skia-autogen.googlecode.com/svn/gm-actual')
358parser.add_argument('--actuals-filename',
epoger@google.com06e626d2013-09-03 17:32:15 +0000359 help=('filename (within builder-specific subdirectories '
360 'of ACTUALS_BASE_URL) to read a summary of results '
361 'from; defaults to %(default)s'),
epoger@google.coma783f2b2013-07-08 17:51:58 +0000362 default='actual-results.json')
epoger@google.comdad53102013-06-12 14:25:30 +0000363parser.add_argument('--add-new', action='store_true',
epoger@google.com06e626d2013-09-03 17:32:15 +0000364 help=('in addition to the standard behavior of '
365 'updating expectations for failing tests, add '
366 'expectations for tests which don\'t have '
367 'expectations yet.'))
368parser.add_argument('--bugs', metavar='BUG', type=int, nargs='+',
369 help=('Skia bug numbers (under '
370 'https://code.google.com/p/skia/issues/list ) which '
371 'pertain to this set of rebaselines.'))
epoger@google.comfd040112013-08-20 16:21:55 +0000372parser.add_argument('--builders', metavar='BUILDER', nargs='+',
epoger@google.com06e626d2013-09-03 17:32:15 +0000373 help=('which platforms to rebaseline; '
epoger@google.com6d28e8d2013-09-18 14:58:47 +0000374 'if unspecified, rebaseline all known platforms '
375 '(see below for a list)'))
epoger@google.coma783f2b2013-07-08 17:51:58 +0000376# TODO(epoger): Add test that exercises --configs argument.
epoger@google.com9166bf52013-05-30 15:46:19 +0000377parser.add_argument('--configs', metavar='CONFIG', nargs='+',
epoger@google.com06e626d2013-09-03 17:32:15 +0000378 help=('which configurations to rebaseline, e.g. '
379 '"--configs 565 8888", as a filter over the full set '
380 'of results in ACTUALS_FILENAME; if unspecified, '
scroggo@google.comd23e6832013-10-10 21:09:24 +0000381 'rebaseline *all* configs that are available. '
382 'Ignored if SKIMAGE is True.'))
epoger@google.coma783f2b2013-07-08 17:51:58 +0000383parser.add_argument('--expectations-filename',
epoger@google.com06e626d2013-09-03 17:32:15 +0000384 help=('filename (under EXPECTATIONS_ROOT) to read '
385 'current expectations from, and to write new '
386 'expectations into (unless a separate '
387 'EXPECTATIONS_FILENAME_OUTPUT has been specified); '
388 'defaults to %(default)s'),
epoger@google.coma783f2b2013-07-08 17:51:58 +0000389 default='expected-results.json')
epoger@google.comc60e7452013-07-24 19:36:51 +0000390parser.add_argument('--expectations-filename-output',
epoger@google.com06e626d2013-09-03 17:32:15 +0000391 help=('filename (under EXPECTATIONS_ROOT) to write '
392 'updated expectations into; by default, overwrites '
393 'the input file (EXPECTATIONS_FILENAME)'),
epoger@google.comc60e7452013-07-24 19:36:51 +0000394 default='')
epoger@google.com99a8ec92013-06-19 18:56:59 +0000395parser.add_argument('--expectations-root',
epoger@google.com06e626d2013-09-03 17:32:15 +0000396 help=('root of expectations directory to update-- should '
397 'contain one or more builder subdirectories. '
scroggo@google.comd23e6832013-10-10 21:09:24 +0000398 'Defaults to %(default)s. If SKIMAGE is set, '
399 ' defaults to ' + gm_json.SKIMAGE_EXPECTATIONS_ROOT),
epoger@google.come94a7d22013-07-23 19:37:03 +0000400 default=os.path.join('expectations', 'gm'))
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000401parser.add_argument('--keep-going-on-failure', action='store_true',
epoger@google.com06e626d2013-09-03 17:32:15 +0000402 help=('instead of halting at the first error encountered, '
403 'keep going and rebaseline as many tests as '
404 'possible, and then report the full set of errors '
405 'at the end'))
406parser.add_argument('--notes',
407 help=('free-form text notes to add to all updated '
408 'expectations'))
epoger@google.coma783f2b2013-07-08 17:51:58 +0000409# TODO(epoger): Add test that exercises --tests argument.
epoger@google.com99ba65a2013-06-05 15:43:37 +0000410parser.add_argument('--tests', metavar='TEST', nargs='+',
epoger@google.com06e626d2013-09-03 17:32:15 +0000411 help=('which tests to rebaseline, e.g. '
412 '"--tests aaclip bigmatrix", as a filter over the '
413 'full set of results in ACTUALS_FILENAME; if '
414 'unspecified, rebaseline *all* tests that are '
scroggo@google.comd23e6832013-10-10 21:09:24 +0000415 'available. Ignored if SKIMAGE is True.'))
epoger@google.com06e626d2013-09-03 17:32:15 +0000416parser.add_argument('--unreviewed', action='store_true',
417 help=('mark all expectations modified by this run as '
418 '"%s": False' %
419 gm_json.JSONKEY_EXPECTEDRESULTS_REVIEWED))
senorblanco@chromium.orgbfc0d6b2013-09-18 19:14:43 +0000420parser.add_argument('--ignore-failure', action='store_true',
421 help=('mark all expectations modified by this run as '
422 '"%s": True' %
423 gm_json.JSONKEY_ACTUALRESULTS_FAILUREIGNORED))
borenet@google.comb6e915d2013-09-16 18:13:13 +0000424parser.add_argument('--from-trybot', action='store_true',
425 help=('pull the actual-results.json file from the '
426 'corresponding trybot, rather than the main builder'))
scroggo@google.comd23e6832013-10-10 21:09:24 +0000427parser.add_argument('--skimage', action='store_true',
428 help=('Rebaseline skimage results instead of gm. Defaults '
429 'to False. If True, TESTS and CONFIGS are ignored, '
430 'and ACTUALS_BASE_URL and EXPECTATIONS_ROOT are set '
431 'to alternate defaults, specific to skimage.'))
epoger@google.com9166bf52013-05-30 15:46:19 +0000432args = parser.parse_args()
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000433exception_handler = ExceptionHandler(
434 keep_going_on_failure=args.keep_going_on_failure)
epoger@google.comfd040112013-08-20 16:21:55 +0000435if args.builders:
436 builders = args.builders
epoger@google.com2a192a82013-08-02 20:54:46 +0000437 missing_json_is_fatal = True
epoger@google.com99a8ec92013-06-19 18:56:59 +0000438else:
epoger@google.comfd040112013-08-20 16:21:55 +0000439 builders = sorted(TEST_BUILDERS)
epoger@google.com2a192a82013-08-02 20:54:46 +0000440 missing_json_is_fatal = False
scroggo@google.comd23e6832013-10-10 21:09:24 +0000441if args.skimage:
442 # Use a different default if --skimage is specified.
443 if args.actuals_base_url == parser.get_default('actuals_base_url'):
444 args.actuals_base_url = gm_json.SKIMAGE_ACTUALS_BASE_URL
445 if args.expectations_root == parser.get_default('expectations_root'):
446 args.expectations_root = gm_json.SKIMAGE_EXPECTATIONS_ROOT
447 # Also ignore TESTS and CONFIGS
448 args.tests = None
449 args.configs = None
epoger@google.comfd040112013-08-20 16:21:55 +0000450for builder in builders:
451 if not builder in TEST_BUILDERS:
452 raise Exception(('unrecognized builder "%s"; ' +
epoger@google.com2a192a82013-08-02 20:54:46 +0000453 'should be one of %s') % (
epoger@google.comfd040112013-08-20 16:21:55 +0000454 builder, TEST_BUILDERS))
epoger@google.com99a8ec92013-06-19 18:56:59 +0000455
epoger@google.comfd040112013-08-20 16:21:55 +0000456 expectations_json_file = os.path.join(args.expectations_root, builder,
epoger@google.com2a192a82013-08-02 20:54:46 +0000457 args.expectations_filename)
458 if os.path.isfile(expectations_json_file):
459 rebaseliner = JsonRebaseliner(
460 expectations_root=args.expectations_root,
461 expectations_input_filename=args.expectations_filename,
462 expectations_output_filename=(args.expectations_filename_output or
463 args.expectations_filename),
464 tests=args.tests, configs=args.configs,
465 actuals_base_url=args.actuals_base_url,
466 actuals_filename=args.actuals_filename,
467 exception_handler=exception_handler,
epoger@google.com06e626d2013-09-03 17:32:15 +0000468 add_new=args.add_new, bugs=args.bugs, notes=args.notes,
borenet@google.comb6e915d2013-09-16 18:13:13 +0000469 mark_unreviewed=args.unreviewed,
senorblanco@chromium.orgbfc0d6b2013-09-18 19:14:43 +0000470 mark_ignore_failure=args.ignore_failure,
borenet@google.comb6e915d2013-09-16 18:13:13 +0000471 from_trybot=args.from_trybot)
epoger@google.com3e7399f2013-07-10 17:23:47 +0000472 try:
epoger@google.comfd040112013-08-20 16:21:55 +0000473 rebaseliner.RebaselineSubdir(builder=builder)
epoger@google.com93acfd22013-09-03 18:27:19 +0000474 except:
475 exception_handler.RaiseExceptionOrContinue()
epoger@google.com2a192a82013-08-02 20:54:46 +0000476 else:
epoger@google.com93acfd22013-09-03 18:27:19 +0000477 try:
478 raise _InternalException('expectations_json_file %s not found' %
479 expectations_json_file)
480 except:
481 exception_handler.RaiseExceptionOrContinue()
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000482
483exception_handler.ReportAllFailures()