Skip to content

Commit

Permalink
Allow webkit-patch rebaseline-cl to read tests names from a file.
Browse files Browse the repository at this point in the history
If there are too many test names to put on the command line, you can
now put the test names into a file, one test per line.  Lines
starting with '#' are ignored.

R=qyearsley@chromium.org

Bug: 
Change-Id: I78b30a5446b7af410de1dfac5be97c3ef1014014
Reviewed-on: https://chromium-review.googlesource.com/696297
Commit-Queue: Stefan Zager <szager@chromium.org>
Reviewed-by: Quinten Yearsley <qyearsley@chromium.org>
Cr-Commit-Position: refs/heads/master@{#508452}
  • Loading branch information
szager-chromium authored and Commit Bot committed Oct 12, 2017
1 parent d8ee494 commit acd4748
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def mtime(self, path):
return 0
self._raise_not_found(path)

def _mktemp(self, suffix='', prefix='tmp', dir=None, **_): # pylint: disable=redefined-builtin
def mktemp(self, suffix='', prefix='tmp', dir=None, **_): # pylint: disable=redefined-builtin
if dir is None:
dir = self.sep + '__im_tmp'
curno = self.current_tmpno
Expand All @@ -256,7 +256,7 @@ class TemporaryDirectory(object):
def __init__(self, fs, **kwargs):
self._kwargs = kwargs
self._filesystem = fs
self._directory_path = fs._mktemp(**kwargs) # pylint: disable=protected-access
self._directory_path = fs.mktemp(**kwargs) # pylint: disable=protected-access
fs.maybe_make_directory(self._directory_path)

def __str__(self):
Expand Down Expand Up @@ -314,7 +314,7 @@ def normpath(self, path):
return path

def open_binary_tempfile(self, suffix=''):
path = self._mktemp(suffix)
path = self.mktemp(suffix)
return (WritableBinaryFileObject(self, path), path)

def open_binary_file_for_reading(self, path):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ class RebaselineCL(AbstractParallelRebaselineCommand):
help_text = 'Fetches new baselines for a CL from test runs on try bots.'
long_help = ('This command downloads new baselines for failing layout '
'tests from archived try job test results. Cross-platform '
'baselines are deduplicated after downloading.')
'baselines are deduplicated after downloading. Without '
'positional parameters or --test-name-file, all failing tests '
'are rebaselined. If positional parameters are provided, '
'they are interpreted as test names to rebaseline.')

show_in_main_help = True
argument_names = '[testname,...]'

def __init__(self):
super(RebaselineCL, self).__init__(options=[
Expand All @@ -47,6 +52,10 @@ def __init__(self):
'from try job results of other platforms.'),
optparse.make_option(
'--no-fill-missing', dest='fill_missing', action='store_false'),
optparse.make_option(
'--test-name-file', dest='test_name_file', default=None,
help='Read names of tests to rebaseline from this file, one '
'test per line.'),
self.no_optimize_option,
self.results_directory_option,
])
Expand All @@ -56,6 +65,11 @@ def execute(self, options, args, tool):
self._tool = tool
self.git_cl = self.git_cl or GitCL(tool)

if args and options.test_name_file:
_log.error('Aborted: Cannot combine --test-name-file and '
'positional parameters.')
return 1

# The WPT manifest is required when iterating through tests
# TestBaselineSet if there are any tests in web-platform-tests.
# TODO(qyearsley): Consider calling ensure_manifest in WebKitPatch.
Expand Down Expand Up @@ -99,7 +113,10 @@ def execute(self, options, args, tool):
'as long as the results are not platform-specific.',
default=self._tool.user.DEFAULT_NO)

if args:
if options.test_name_file:
test_baseline_set = self._make_test_baseline_set_from_file(
options.test_name_file, jobs_to_results)
elif args:
test_baseline_set = self._make_test_baseline_set_for_tests(
args, jobs_to_results)
else:
Expand Down Expand Up @@ -212,6 +229,22 @@ def _fetch_results(self, jobs):
results[build] = layout_test_results
return results

def _make_test_baseline_set_from_file(self, filename, builds_to_results):
test_baseline_set = TestBaselineSet(self._tool)
try:
with self._tool.filesystem.open_text_file_for_reading(filename) as fh:
_log.info('Reading list of tests to rebaseline '
'from %s', filename)
for test in fh.readlines():
test = test.strip()
if not test or test.startswith('#'):
continue
for build in builds_to_results:
test_baseline_set.add(test, build)
except IOError:
_log.info('Could not read test names from %s', filename)
return test_baseline_set

def _make_test_baseline_set_for_tests(self, tests, builds_to_results):
test_baseline_set = TestBaselineSet(self._tool)
for test in tests:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import json
import optparse
import textwrap

from webkitpy.common.checkout.git_mock import MockGit
from webkitpy.common.net.buildbot import Build
Expand Down Expand Up @@ -114,6 +115,7 @@ def command_options(**kwargs):
'fill_missing': None,
'optimize': True,
'results_directory': None,
'test_name_file': None,
'verbose': False,
}
options.update(kwargs)
Expand All @@ -133,6 +135,29 @@ def test_execute_basic(self):
'INFO: Rebaselining two/image-fail.html\n',
])

def test_execute_with_test_name_file(self):
fs = self.mac_port.host.filesystem
test_name_file = fs.mktemp()
fs.write_text_file(test_name_file, textwrap.dedent('''
one/flaky-fail.html
one/missing.html
# one/slow-fail.html
#
one/text-fail.html
two/image-fail.html '''))
exit_code = self.command.execute(
self.command_options(test_name_file=test_name_file), [], self.tool)
self.assertEqual(exit_code, 0)
self.assertLog([
'INFO: Finished try jobs found for all try bots.\n',
'INFO: Reading list of tests to rebaseline from %s\n' % test_name_file,
'INFO: Rebaselining one/flaky-fail.html\n',
'INFO: Rebaselining one/missing.html\n',
'INFO: Rebaselining one/text-fail.html\n',
'INFO: Rebaselining two/image-fail.html\n',
])

def test_execute_with_no_issue_number_aborts(self):
# If the user hasn't uploaded a CL, an error message is printed.
self.command.git_cl = MockGitCL(self.tool, issue_number='None')
Expand Down

0 comments on commit acd4748

Please sign in to comment.