blob: 294a368f140a5e94917540ba36ccfa6fdc42ba23 [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',
epoger@google.com44f165f2013-08-24 20:45:31 +000077 'Test-Ubuntu12-ShuttleA-HD2000-x86_64-Release-Valgrind',
senorblanco@chromium.org9e3b4852014-04-30 16:11:50 +000078 'Test-Ubuntu12-ShuttleA-GTX660-x86-Debug',
79 'Test-Ubuntu12-ShuttleA-GTX660-x86-Release',
80 'Test-Ubuntu12-ShuttleA-GTX660-x86_64-Debug',
81 'Test-Ubuntu12-ShuttleA-GTX660-x86_64-Release',
82 'Test-Ubuntu13.10-ShuttleA-NoGPU-x86_64-Debug',
epoger@google.com44f165f2013-08-24 20:45:31 +000083 'Test-Win7-ShuttleA-HD2000-x86-Debug',
84 'Test-Win7-ShuttleA-HD2000-x86-Debug-ANGLE',
85 'Test-Win7-ShuttleA-HD2000-x86-Debug-DirectWrite',
86 'Test-Win7-ShuttleA-HD2000-x86-Release',
87 'Test-Win7-ShuttleA-HD2000-x86-Release-ANGLE',
88 'Test-Win7-ShuttleA-HD2000-x86-Release-DirectWrite',
89 'Test-Win7-ShuttleA-HD2000-x86_64-Debug',
90 'Test-Win7-ShuttleA-HD2000-x86_64-Release',
commit-bot@chromium.orgbf8ba652013-12-17 17:29:33 +000091 'Test-Win8-ShuttleA-GTX660-x86-Debug',
92 'Test-Win8-ShuttleA-GTX660-x86-Release',
commit-bot@chromium.orgbf8ba652013-12-17 17:29:33 +000093 'Test-Win8-ShuttleA-GTX660-x86_64-Debug',
94 'Test-Win8-ShuttleA-GTX660-x86_64-Release',
95 'Test-Win8-ShuttleA-HD7770-x86-Debug',
96 'Test-Win8-ShuttleA-HD7770-x86-Release',
97 'Test-Win8-ShuttleA-HD7770-x86_64-Debug',
98 'Test-Win8-ShuttleA-HD7770-x86_64-Release',
epoger@google.com44f165f2013-08-24 20:45:31 +000099]
epoger@google.com9166bf52013-05-30 15:46:19 +0000100
borenet@google.comb6e915d2013-09-16 18:13:13 +0000101# TODO: Get this from builder_name_schema in buildbot.
102TRYBOT_SUFFIX = '-Trybot'
103
104
epoger@google.com66ba9f92013-07-11 19:20:30 +0000105class _InternalException(Exception):
epoger@google.com2a192a82013-08-02 20:54:46 +0000106 pass
epoger@google.comdb29a312013-06-04 14:58:47 +0000107
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000108class ExceptionHandler(object):
epoger@google.com93acfd22013-09-03 18:27:19 +0000109 """ Object that handles exceptions, either raising them immediately or
110 collecting them to display later on."""
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000111
epoger@google.com2a192a82013-08-02 20:54:46 +0000112 # params:
epoger@google.com2a192a82013-08-02 20:54:46 +0000113 def __init__(self, keep_going_on_failure=False):
epoger@google.com93acfd22013-09-03 18:27:19 +0000114 """
115 params:
116 keep_going_on_failure: if False, report failures and quit right away;
117 if True, collect failures until
118 ReportAllFailures() is called
119 """
epoger@google.com2a192a82013-08-02 20:54:46 +0000120 self._keep_going_on_failure = keep_going_on_failure
121 self._failures_encountered = []
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000122
epoger@google.com93acfd22013-09-03 18:27:19 +0000123 def RaiseExceptionOrContinue(self):
124 """ We have encountered an exception; either collect the info and keep
125 going, or exit the program right away."""
126 # Get traceback information about the most recently raised exception.
127 exc_info = sys.exc_info()
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000128
epoger@google.com2a192a82013-08-02 20:54:46 +0000129 if self._keep_going_on_failure:
epoger@google.com93acfd22013-09-03 18:27:19 +0000130 print >> sys.stderr, ('WARNING: swallowing exception %s' %
131 repr(exc_info[1]))
132 self._failures_encountered.append(exc_info)
epoger@google.com2a192a82013-08-02 20:54:46 +0000133 else:
epoger@google.com2a192a82013-08-02 20:54:46 +0000134 print >> sys.stderr, (
epoger@google.com80f9cf12013-09-06 17:26:09 +0000135 '\nHalting at first exception.\n' +
136 'Please file a bug to epoger@google.com at ' +
137 'https://code.google.com/p/skia/issues/entry, containing the ' +
138 'command you ran and the following stack trace.\n\n' +
139 'Afterwards, you can re-run with the --keep-going-on-failure ' +
140 'option set.\n')
epoger@google.com93acfd22013-09-03 18:27:19 +0000141 raise exc_info[1], None, exc_info[2]
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000142
epoger@google.com2a192a82013-08-02 20:54:46 +0000143 def ReportAllFailures(self):
144 if self._failures_encountered:
145 print >> sys.stderr, ('Encountered %d failures (see above).' %
146 len(self._failures_encountered))
epoger@google.com93acfd22013-09-03 18:27:19 +0000147 sys.exit(1)
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000148
149
epoger@google.com99a8ec92013-06-19 18:56:59 +0000150# Object that rebaselines a JSON expectations file (not individual image files).
epoger@google.com99a8ec92013-06-19 18:56:59 +0000151class JsonRebaseliner(object):
epoger@google.com9166bf52013-05-30 15:46:19 +0000152
epoger@google.com2a192a82013-08-02 20:54:46 +0000153 # params:
154 # expectations_root: root directory of all expectations JSON files
155 # expectations_input_filename: filename (under expectations_root) of JSON
156 # expectations file to read; typically
157 # "expected-results.json"
158 # expectations_output_filename: filename (under expectations_root) to
159 # which updated expectations should be
160 # written; typically the same as
161 # expectations_input_filename, to overwrite
162 # the old content
163 # actuals_base_url: base URL from which to read actual-result JSON files
164 # actuals_filename: filename (under actuals_base_url) from which to read a
165 # summary of results; typically "actual-results.json"
166 # exception_handler: reference to rebaseline.ExceptionHandler object
167 # tests: list of tests to rebaseline, or None if we should rebaseline
168 # whatever files the JSON results summary file tells us to
169 # configs: which configs to run for each test, or None if we should
170 # rebaseline whatever configs the JSON results summary file tells
171 # us to
172 # add_new: if True, add expectations for tests which don't have any yet
bsalomon@google.com46484ec2013-10-16 15:10:45 +0000173 # add_ignored: if True, add expectations for tests for which failures are
174 # currently ignored
epoger@google.com06e626d2013-09-03 17:32:15 +0000175 # bugs: optional list of bug numbers which pertain to these expectations
176 # notes: free-form text notes to add to all updated expectations
177 # mark_unreviewed: if True, mark these expectations as NOT having been
178 # reviewed by a human; otherwise, leave that field blank.
179 # Currently, there is no way to make this script mark
180 # expectations as reviewed-by-human=True.
181 # TODO(epoger): Add that capability to a review tool.
senorblanco@chromium.orgbfc0d6b2013-09-18 19:14:43 +0000182 # mark_ignore_failure: if True, mark failures of a given test as being
183 # ignored.
scroggo@google.comd23e6832013-10-10 21:09:24 +0000184 # from_trybot: if True, read actual-result JSON files generated from a
185 # trybot run rather than a waterfall run.
epoger@google.com2a192a82013-08-02 20:54:46 +0000186 def __init__(self, expectations_root, expectations_input_filename,
187 expectations_output_filename, actuals_base_url,
188 actuals_filename, exception_handler,
bsalomon@google.com46484ec2013-10-16 15:10:45 +0000189 tests=None, configs=None, add_new=False, add_ignored=False,
190 bugs=None, notes=None, mark_unreviewed=None,
191 mark_ignore_failure=False, from_trybot=False):
epoger@google.com2a192a82013-08-02 20:54:46 +0000192 self._expectations_root = expectations_root
193 self._expectations_input_filename = expectations_input_filename
194 self._expectations_output_filename = expectations_output_filename
195 self._tests = tests
196 self._configs = configs
197 self._actuals_base_url = actuals_base_url
198 self._actuals_filename = actuals_filename
199 self._exception_handler = exception_handler
200 self._add_new = add_new
bsalomon@google.com46484ec2013-10-16 15:10:45 +0000201 self._add_ignored = add_ignored
epoger@google.com06e626d2013-09-03 17:32:15 +0000202 self._bugs = bugs
203 self._notes = notes
204 self._mark_unreviewed = mark_unreviewed
senorblanco@chromium.orgbfc0d6b2013-09-18 19:14:43 +0000205 self._mark_ignore_failure = mark_ignore_failure;
scroggo@google.comd23e6832013-10-10 21:09:24 +0000206 if self._tests or self._configs:
207 self._image_filename_re = re.compile(gm_json.IMAGE_FILENAME_PATTERN)
208 else:
209 self._image_filename_re = None
epoger@google.com2a192a82013-08-02 20:54:46 +0000210 self._using_svn = os.path.isdir(os.path.join(expectations_root, '.svn'))
borenet@google.comb6e915d2013-09-16 18:13:13 +0000211 self._from_trybot = from_trybot
epoger@google.com27e1c002013-07-24 15:38:39 +0000212
epoger@google.com2a192a82013-08-02 20:54:46 +0000213 # Executes subprocess.call(cmd).
214 # Raises an Exception if the command fails.
215 def _Call(self, cmd):
216 if subprocess.call(cmd) != 0:
217 raise _InternalException('error running command: ' + ' '.join(cmd))
epoger@google.com9166bf52013-05-30 15:46:19 +0000218
epoger@google.com2a192a82013-08-02 20:54:46 +0000219 # Returns the full contents of filepath, as a single string.
220 # If filepath looks like a URL, try to read it that way instead of as
221 # a path on local storage.
222 #
223 # Raises _InternalException if there is a problem.
224 def _GetFileContents(self, filepath):
225 if filepath.startswith('http:') or filepath.startswith('https:'):
226 try:
227 return urllib2.urlopen(filepath).read()
228 except urllib2.HTTPError as e:
229 raise _InternalException('unable to read URL %s: %s' % (
230 filepath, e))
231 else:
232 return open(filepath, 'r').read()
epoger@google.com99ba65a2013-06-05 15:43:37 +0000233
epoger@google.com2a192a82013-08-02 20:54:46 +0000234 # Returns a dictionary of actual results from actual-results.json file.
235 #
236 # The dictionary returned has this format:
237 # {
238 # u'imageblur_565.png': [u'bitmap-64bitMD5', 3359963596899141322],
239 # u'imageblur_8888.png': [u'bitmap-64bitMD5', 4217923806027861152],
240 # u'shadertext3_8888.png': [u'bitmap-64bitMD5', 3713708307125704716]
241 # }
242 #
243 # If the JSON actual result summary file cannot be loaded, logs a warning
244 # message and returns None.
245 # If the JSON actual result summary file can be loaded, but we have
246 # trouble parsing it, raises an Exception.
247 #
248 # params:
249 # json_url: URL pointing to a JSON actual result summary file
250 # sections: a list of section names to include in the results, e.g.
251 # [gm_json.JSONKEY_ACTUALRESULTS_FAILED,
252 # gm_json.JSONKEY_ACTUALRESULTS_NOCOMPARISON] ;
253 # if None, then include ALL sections.
254 def _GetActualResults(self, json_url, sections=None):
255 try:
256 json_contents = self._GetFileContents(json_url)
257 except _InternalException:
258 print >> sys.stderr, (
259 'could not read json_url %s ; skipping this platform.' %
260 json_url)
261 return None
262 json_dict = gm_json.LoadFromString(json_contents)
263 results_to_return = {}
264 actual_results = json_dict[gm_json.JSONKEY_ACTUALRESULTS]
265 if not sections:
266 sections = actual_results.keys()
267 for section in sections:
268 section_results = actual_results[section]
269 if section_results:
270 results_to_return.update(section_results)
271 return results_to_return
epoger@google.come78d2072013-06-12 17:44:14 +0000272
epoger@google.com2a192a82013-08-02 20:54:46 +0000273 # Rebaseline all tests/types we specified in the constructor,
epoger@google.comfd040112013-08-20 16:21:55 +0000274 # within this builder's subdirectory in expectations/gm .
epoger@google.com2a192a82013-08-02 20:54:46 +0000275 #
276 # params:
epoger@google.com2a192a82013-08-02 20:54:46 +0000277 # builder : e.g. 'Test-Win7-ShuttleA-HD2000-x86-Release'
epoger@google.comfd040112013-08-20 16:21:55 +0000278 def RebaselineSubdir(self, builder):
epoger@google.com2a192a82013-08-02 20:54:46 +0000279 # Read in the actual result summary, and extract all the tests whose
280 # results we need to update.
borenet@google.comb6e915d2013-09-16 18:13:13 +0000281 results_builder = str(builder)
282 if self._from_trybot:
283 results_builder = results_builder + TRYBOT_SUFFIX
284 actuals_url = '/'.join([self._actuals_base_url, results_builder,
285 self._actuals_filename])
epoger@google.com06e626d2013-09-03 17:32:15 +0000286 # Only update results for tests that are currently failing.
287 # We don't want to rewrite results for tests that are already succeeding,
288 # because we don't want to add annotation fields (such as
289 # JSONKEY_EXPECTEDRESULTS_BUGS) except for tests whose expectations we
290 # are actually modifying.
epoger@google.com7f5f6e62013-09-05 17:19:37 +0000291 sections = [gm_json.JSONKEY_ACTUALRESULTS_FAILED]
epoger@google.com2a192a82013-08-02 20:54:46 +0000292 if self._add_new:
293 sections.append(gm_json.JSONKEY_ACTUALRESULTS_NOCOMPARISON)
bsalomon@google.com46484ec2013-10-16 15:10:45 +0000294 if self._add_ignored:
295 sections.append(gm_json.JSONKEY_ACTUALRESULTS_FAILUREIGNORED)
epoger@google.com2a192a82013-08-02 20:54:46 +0000296 results_to_update = self._GetActualResults(json_url=actuals_url,
297 sections=sections)
epoger@google.come78d2072013-06-12 17:44:14 +0000298
epoger@google.com2a192a82013-08-02 20:54:46 +0000299 # Read in current expectations.
300 expectations_input_filepath = os.path.join(
epoger@google.comfd040112013-08-20 16:21:55 +0000301 self._expectations_root, builder, self._expectations_input_filename)
epoger@google.com2a192a82013-08-02 20:54:46 +0000302 expectations_dict = gm_json.LoadFromFile(expectations_input_filepath)
epoger@google.com93acfd22013-09-03 18:27:19 +0000303 expected_results = expectations_dict.get(gm_json.JSONKEY_EXPECTEDRESULTS)
304 if not expected_results:
305 expected_results = {}
306 expectations_dict[gm_json.JSONKEY_EXPECTEDRESULTS] = expected_results
epoger@google.coma783f2b2013-07-08 17:51:58 +0000307
epoger@google.com2a192a82013-08-02 20:54:46 +0000308 # Update the expectations in memory, skipping any tests/configs that
309 # the caller asked to exclude.
310 skipped_images = []
311 if results_to_update:
312 for (image_name, image_results) in results_to_update.iteritems():
scroggo@google.comd23e6832013-10-10 21:09:24 +0000313 if self._image_filename_re:
314 (test, config) = self._image_filename_re.match(image_name).groups()
315 if self._tests:
316 if test not in self._tests:
317 skipped_images.append(image_name)
318 continue
319 if self._configs:
320 if config not in self._configs:
321 skipped_images.append(image_name)
322 continue
epoger@google.com2a192a82013-08-02 20:54:46 +0000323 if not expected_results.get(image_name):
324 expected_results[image_name] = {}
epoger@google.com06e626d2013-09-03 17:32:15 +0000325 expected_results[image_name]\
326 [gm_json.JSONKEY_EXPECTEDRESULTS_ALLOWEDDIGESTS]\
327 = [image_results]
328 if self._mark_unreviewed:
329 expected_results[image_name]\
330 [gm_json.JSONKEY_EXPECTEDRESULTS_REVIEWED]\
331 = False
senorblanco@chromium.orgbfc0d6b2013-09-18 19:14:43 +0000332 if self._mark_ignore_failure:
333 expected_results[image_name]\
334 [gm_json.JSONKEY_EXPECTEDRESULTS_IGNOREFAILURE]\
335 = True
epoger@google.com06e626d2013-09-03 17:32:15 +0000336 if self._bugs:
337 expected_results[image_name]\
338 [gm_json.JSONKEY_EXPECTEDRESULTS_BUGS]\
339 = self._bugs
340 if self._notes:
341 expected_results[image_name]\
342 [gm_json.JSONKEY_EXPECTEDRESULTS_NOTES]\
343 = self._notes
epoger@google.coma783f2b2013-07-08 17:51:58 +0000344
epoger@google.com2a192a82013-08-02 20:54:46 +0000345 # Write out updated expectations.
346 expectations_output_filepath = os.path.join(
epoger@google.comfd040112013-08-20 16:21:55 +0000347 self._expectations_root, builder, self._expectations_output_filename)
epoger@google.com2a192a82013-08-02 20:54:46 +0000348 gm_json.WriteToFile(expectations_dict, expectations_output_filepath)
epoger@google.coma783f2b2013-07-08 17:51:58 +0000349
epoger@google.com2a192a82013-08-02 20:54:46 +0000350 # Mark the JSON file as plaintext, so text-style diffs can be applied.
351 # Fixes https://code.google.com/p/skia/issues/detail?id=1442
352 if self._using_svn:
353 self._Call(['svn', 'propset', '--quiet', 'svn:mime-type',
354 'text/x-json', expectations_output_filepath])
epoger@google.comec3397b2013-05-29 17:09:43 +0000355
epoger@google.com9166bf52013-05-30 15:46:19 +0000356# main...
epoger@google.comec3397b2013-05-29 17:09:43 +0000357
epoger@google.com6d28e8d2013-09-18 14:58:47 +0000358parser = argparse.ArgumentParser(
359 formatter_class=argparse.RawDescriptionHelpFormatter,
360 epilog='Here is the full set of builders we know about:' +
361 '\n '.join([''] + sorted(TEST_BUILDERS)))
epoger@google.coma783f2b2013-07-08 17:51:58 +0000362parser.add_argument('--actuals-base-url',
epoger@google.com06e626d2013-09-03 17:32:15 +0000363 help=('base URL from which to read files containing JSON '
364 'summaries of actual GM results; defaults to '
scroggo@google.comd23e6832013-10-10 21:09:24 +0000365 '%(default)s. To get a specific revision (useful for '
366 'trybots) replace "svn" with "svn-history/r123". '
367 'If SKIMAGE is True, defaults to ' +
368 gm_json.SKIMAGE_ACTUALS_BASE_URL),
epoger@google.coma783f2b2013-07-08 17:51:58 +0000369 default='http://skia-autogen.googlecode.com/svn/gm-actual')
370parser.add_argument('--actuals-filename',
epoger@google.com06e626d2013-09-03 17:32:15 +0000371 help=('filename (within builder-specific subdirectories '
372 'of ACTUALS_BASE_URL) to read a summary of results '
373 'from; defaults to %(default)s'),
epoger@google.coma783f2b2013-07-08 17:51:58 +0000374 default='actual-results.json')
epoger@google.comdad53102013-06-12 14:25:30 +0000375parser.add_argument('--add-new', action='store_true',
epoger@google.com06e626d2013-09-03 17:32:15 +0000376 help=('in addition to the standard behavior of '
377 'updating expectations for failing tests, add '
378 'expectations for tests which don\'t have '
379 'expectations yet.'))
bsalomon@google.com46484ec2013-10-16 15:10:45 +0000380parser.add_argument('--add-ignored', action='store_true',
381 help=('in addition to the standard behavior of '
382 'updating expectations for failing tests, add '
383 'expectations for tests for which failures are '
384 'currently ignored.'))
epoger@google.com06e626d2013-09-03 17:32:15 +0000385parser.add_argument('--bugs', metavar='BUG', type=int, nargs='+',
386 help=('Skia bug numbers (under '
387 'https://code.google.com/p/skia/issues/list ) which '
388 'pertain to this set of rebaselines.'))
epoger@google.comfd040112013-08-20 16:21:55 +0000389parser.add_argument('--builders', metavar='BUILDER', nargs='+',
epoger@google.com06e626d2013-09-03 17:32:15 +0000390 help=('which platforms to rebaseline; '
epoger@google.com6d28e8d2013-09-18 14:58:47 +0000391 'if unspecified, rebaseline all known platforms '
392 '(see below for a list)'))
epoger@google.coma783f2b2013-07-08 17:51:58 +0000393# TODO(epoger): Add test that exercises --configs argument.
epoger@google.com9166bf52013-05-30 15:46:19 +0000394parser.add_argument('--configs', metavar='CONFIG', nargs='+',
epoger@google.com06e626d2013-09-03 17:32:15 +0000395 help=('which configurations to rebaseline, e.g. '
396 '"--configs 565 8888", as a filter over the full set '
397 'of results in ACTUALS_FILENAME; if unspecified, '
scroggo@google.com5187c432013-10-22 00:42:46 +0000398 'rebaseline *all* configs that are available.'))
epoger@google.coma783f2b2013-07-08 17:51:58 +0000399parser.add_argument('--expectations-filename',
epoger@google.com06e626d2013-09-03 17:32:15 +0000400 help=('filename (under EXPECTATIONS_ROOT) to read '
401 'current expectations from, and to write new '
402 'expectations into (unless a separate '
403 'EXPECTATIONS_FILENAME_OUTPUT has been specified); '
404 'defaults to %(default)s'),
epoger@google.coma783f2b2013-07-08 17:51:58 +0000405 default='expected-results.json')
epoger@google.comc60e7452013-07-24 19:36:51 +0000406parser.add_argument('--expectations-filename-output',
epoger@google.com06e626d2013-09-03 17:32:15 +0000407 help=('filename (under EXPECTATIONS_ROOT) to write '
408 'updated expectations into; by default, overwrites '
409 'the input file (EXPECTATIONS_FILENAME)'),
epoger@google.comc60e7452013-07-24 19:36:51 +0000410 default='')
epoger@google.com99a8ec92013-06-19 18:56:59 +0000411parser.add_argument('--expectations-root',
epoger@google.com06e626d2013-09-03 17:32:15 +0000412 help=('root of expectations directory to update-- should '
413 'contain one or more builder subdirectories. '
scroggo@google.comd23e6832013-10-10 21:09:24 +0000414 'Defaults to %(default)s. If SKIMAGE is set, '
415 ' defaults to ' + gm_json.SKIMAGE_EXPECTATIONS_ROOT),
epoger@google.come94a7d22013-07-23 19:37:03 +0000416 default=os.path.join('expectations', 'gm'))
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000417parser.add_argument('--keep-going-on-failure', action='store_true',
epoger@google.com06e626d2013-09-03 17:32:15 +0000418 help=('instead of halting at the first error encountered, '
419 'keep going and rebaseline as many tests as '
420 'possible, and then report the full set of errors '
421 'at the end'))
422parser.add_argument('--notes',
423 help=('free-form text notes to add to all updated '
424 'expectations'))
epoger@google.coma783f2b2013-07-08 17:51:58 +0000425# TODO(epoger): Add test that exercises --tests argument.
epoger@google.com99ba65a2013-06-05 15:43:37 +0000426parser.add_argument('--tests', metavar='TEST', nargs='+',
epoger@google.com06e626d2013-09-03 17:32:15 +0000427 help=('which tests to rebaseline, e.g. '
428 '"--tests aaclip bigmatrix", as a filter over the '
429 'full set of results in ACTUALS_FILENAME; if '
430 'unspecified, rebaseline *all* tests that are '
scroggo@google.com5187c432013-10-22 00:42:46 +0000431 'available.'))
epoger@google.com06e626d2013-09-03 17:32:15 +0000432parser.add_argument('--unreviewed', action='store_true',
433 help=('mark all expectations modified by this run as '
434 '"%s": False' %
435 gm_json.JSONKEY_EXPECTEDRESULTS_REVIEWED))
senorblanco@chromium.orgbfc0d6b2013-09-18 19:14:43 +0000436parser.add_argument('--ignore-failure', action='store_true',
437 help=('mark all expectations modified by this run as '
438 '"%s": True' %
439 gm_json.JSONKEY_ACTUALRESULTS_FAILUREIGNORED))
borenet@google.comb6e915d2013-09-16 18:13:13 +0000440parser.add_argument('--from-trybot', action='store_true',
441 help=('pull the actual-results.json file from the '
442 'corresponding trybot, rather than the main builder'))
scroggo@google.comd23e6832013-10-10 21:09:24 +0000443parser.add_argument('--skimage', action='store_true',
444 help=('Rebaseline skimage results instead of gm. Defaults '
445 'to False. If True, TESTS and CONFIGS are ignored, '
446 'and ACTUALS_BASE_URL and EXPECTATIONS_ROOT are set '
447 'to alternate defaults, specific to skimage.'))
epoger@google.com9166bf52013-05-30 15:46:19 +0000448args = parser.parse_args()
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000449exception_handler = ExceptionHandler(
450 keep_going_on_failure=args.keep_going_on_failure)
epoger@google.comfd040112013-08-20 16:21:55 +0000451if args.builders:
452 builders = args.builders
epoger@google.com2a192a82013-08-02 20:54:46 +0000453 missing_json_is_fatal = True
epoger@google.com99a8ec92013-06-19 18:56:59 +0000454else:
epoger@google.comfd040112013-08-20 16:21:55 +0000455 builders = sorted(TEST_BUILDERS)
epoger@google.com2a192a82013-08-02 20:54:46 +0000456 missing_json_is_fatal = False
scroggo@google.comd23e6832013-10-10 21:09:24 +0000457if args.skimage:
458 # Use a different default if --skimage is specified.
459 if args.actuals_base_url == parser.get_default('actuals_base_url'):
460 args.actuals_base_url = gm_json.SKIMAGE_ACTUALS_BASE_URL
461 if args.expectations_root == parser.get_default('expectations_root'):
462 args.expectations_root = gm_json.SKIMAGE_EXPECTATIONS_ROOT
epoger@google.comfd040112013-08-20 16:21:55 +0000463for builder in builders:
464 if not builder in TEST_BUILDERS:
465 raise Exception(('unrecognized builder "%s"; ' +
epoger@google.com2a192a82013-08-02 20:54:46 +0000466 'should be one of %s') % (
epoger@google.comfd040112013-08-20 16:21:55 +0000467 builder, TEST_BUILDERS))
epoger@google.com99a8ec92013-06-19 18:56:59 +0000468
epoger@google.comfd040112013-08-20 16:21:55 +0000469 expectations_json_file = os.path.join(args.expectations_root, builder,
epoger@google.com2a192a82013-08-02 20:54:46 +0000470 args.expectations_filename)
471 if os.path.isfile(expectations_json_file):
472 rebaseliner = JsonRebaseliner(
473 expectations_root=args.expectations_root,
474 expectations_input_filename=args.expectations_filename,
475 expectations_output_filename=(args.expectations_filename_output or
476 args.expectations_filename),
477 tests=args.tests, configs=args.configs,
478 actuals_base_url=args.actuals_base_url,
479 actuals_filename=args.actuals_filename,
480 exception_handler=exception_handler,
bsalomon@google.com46484ec2013-10-16 15:10:45 +0000481 add_new=args.add_new, add_ignored=args.add_ignored,
482 bugs=args.bugs, notes=args.notes,
borenet@google.comb6e915d2013-09-16 18:13:13 +0000483 mark_unreviewed=args.unreviewed,
senorblanco@chromium.orgbfc0d6b2013-09-18 19:14:43 +0000484 mark_ignore_failure=args.ignore_failure,
borenet@google.comb6e915d2013-09-16 18:13:13 +0000485 from_trybot=args.from_trybot)
epoger@google.com3e7399f2013-07-10 17:23:47 +0000486 try:
epoger@google.comfd040112013-08-20 16:21:55 +0000487 rebaseliner.RebaselineSubdir(builder=builder)
epoger@google.com93acfd22013-09-03 18:27:19 +0000488 except:
489 exception_handler.RaiseExceptionOrContinue()
epoger@google.com2a192a82013-08-02 20:54:46 +0000490 else:
epoger@google.com93acfd22013-09-03 18:27:19 +0000491 try:
492 raise _InternalException('expectations_json_file %s not found' %
493 expectations_json_file)
494 except:
495 exception_handler.RaiseExceptionOrContinue()
epoger@google.comffcbdbf2013-07-16 17:35:39 +0000496
497exception_handler.ReportAllFailures()