Commit 45400a6f authored by nednguyen's avatar nednguyen Committed by Commit bot

[Telemetry] Add results filtering.

BUG=439497

Review URL: https://codereview.chromium.org/938743002

Cr-Commit-Position: refs/heads/master@{#316941}
parent 66e4d216
......@@ -138,6 +138,20 @@ class Benchmark(command_line.Command):
def ProcessCommandLineArgs(cls, parser, args):
pass
@classmethod
def ValueCanBeAddedPredicate(cls, value): # pylint: disable=unused-argument
""" Returns whether |value| can be added to the test results.
Override this method to customize the logic of adding values to test
results.
Args:
value: a value.Value instance.
Returns: a boolean. True if value should be added to the test results and
False otherwise.
"""
return True
def CustomizeBrowserOptions(self, options):
"""Add browser options that are required by this benchmark."""
......@@ -175,7 +189,8 @@ class Benchmark(command_line.Command):
self._DownloadGeneratedProfileArchive(finder_options)
benchmark_metadata = self.GetMetadata()
results = results_options.CreateResults(benchmark_metadata, finder_options)
results = results_options.CreateResults(
benchmark_metadata, finder_options, self.ValueCanBeAddedPredicate)
try:
user_story_runner.Run(pt, us, expectations, finder_options, results,
max_failures=self._max_failures)
......
......@@ -22,7 +22,8 @@ from telemetry.value import trace
class PageTestResults(object):
def __init__(self, output_stream=None, output_formatters=None,
progress_reporter=None, trace_tag='', output_dir=None):
progress_reporter=None, trace_tag='', output_dir=None,
value_can_be_added_predicate=lambda v: True):
"""
Args:
output_stream: The output stream to use to write test results.
......@@ -31,8 +32,13 @@ class PageTestResults(object):
as CsvOutputFormatter, which output the test results as CSV.
progress_reporter: An instance of progress_reporter.ProgressReporter,
to be used to output test status/results progressively.
trace_tag: A string to append to the buildbot trace
name. Currently only used for buildbot.
trace_tag: A string to append to the buildbot trace name. Currently only
used for buildbot.
output_dir: A string specified the directory where to store the test
artifacts, e.g: trace, videos,...
value_can_be_added_predicate: A function that takes an value.Value
instance as input. It returns True if the value can be added to the
test results and False otherwise.
"""
# TODO(chrishenry): Figure out if trace_tag is still necessary.
......@@ -45,6 +51,7 @@ class PageTestResults(object):
output_formatters if output_formatters is not None else [])
self._trace_tag = trace_tag
self._output_dir = output_dir
self._value_can_be_added_predicate = value_can_be_added_predicate
self._current_page_run = None
self._all_page_runs = []
......@@ -148,6 +155,8 @@ class PageTestResults(object):
def AddValue(self, value):
assert self._current_page_run, 'Not currently running test.'
self._ValidateValue(value)
if not self._value_can_be_added_predicate(value):
return
# TODO(eakuefner/chrishenry): Add only one skip per pagerun assert here
self._current_page_run.AddValue(value)
self._progress_reporter.DidAddValue(value)
......
......@@ -45,6 +45,7 @@ class PageTestResultsTest(base_test_results_unittest.BaseTestResultsUnittest):
self.assertTrue(results.all_page_runs[0].failed)
self.assertTrue(results.all_page_runs[1].ok)
def testSkips(self):
results = page_test_results.PageTestResults()
results.WillRunPage(self.pages[0])
......@@ -84,6 +85,38 @@ class PageTestResultsTest(base_test_results_unittest.BaseTestResultsUnittest):
values = results.FindAllPageSpecificValuesNamed('a')
assert len(values) == 2
def testResultsFiltering(self):
def AcceptValueNamed_a(value):
return value.name == 'a'
results = page_test_results.PageTestResults(
value_can_be_added_predicate=AcceptValueNamed_a)
results.WillRunPage(self.pages[0])
results.AddValue(scalar.ScalarValue(self.pages[0], 'a', 'seconds', 3))
results.AddValue(scalar.ScalarValue(self.pages[0], 'b', 'seconds', 3))
results.DidRunPage(self.pages[0])
results.WillRunPage(self.pages[1])
results.AddValue(scalar.ScalarValue(self.pages[1], 'a', 'seconds', 3))
results.AddValue(scalar.ScalarValue(self.pages[1], 'd', 'seconds', 3))
results.DidRunPage(self.pages[1])
results.PrintSummary()
values = results.FindPageSpecificValuesForPage(self.pages[0], 'a')
self.assertEquals(1, len(values))
v = values[0]
self.assertEquals(v.name, 'a')
self.assertEquals(v.page, self.pages[0])
values = results.FindPageSpecificValuesForPage(self.pages[0], 'b')
self.assertEquals(0, len(values))
values = results.FindAllPageSpecificValuesNamed('a')
self.assertEquals(len(values), 2)
values = results.all_page_specific_values
self.assertEquals(len(values), 2)
def testUrlIsInvalidValue(self):
results = page_test_results.PageTestResults()
results.WillRunPage(self.pages[0])
......
......@@ -107,7 +107,8 @@ def _GetProgressReporter(output_skipped_tests_summary, suppress_gtest_report):
sys.stdout, output_skipped_tests_summary=output_skipped_tests_summary)
def CreateResults(benchmark_metadata, options):
def CreateResults(benchmark_metadata, options,
value_can_be_added_predicate=lambda v: True):
"""
Args:
options: Contains the options specified in AddResultsOptions.
......@@ -166,4 +167,5 @@ def CreateResults(benchmark_metadata, options):
options.suppress_gtest_report)
return page_test_results.PageTestResults(
output_formatters=output_formatters, progress_reporter=reporter,
output_dir=options.output_dir)
output_dir=options.output_dir,
value_can_be_added_predicate=value_can_be_added_predicate)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment