Commit 0c9474e4 authored by Juan Antonio Navarro Perez's avatar Juan Antonio Navarro Perez Committed by Commit Bot

[tools/perf] Add test for return_code of benchmark_runner

Prevent issues like crbug.com/985712 happening again.

Bug: 990472
Bug: 985712
Change-Id: I6cfa17ec39076f17b6a3bf35b0430f778c05d5ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1736896Reviewed-by: default avatarCaleb Rouleau <crouleau@chromium.org>
Commit-Queue: Caleb Rouleau <crouleau@chromium.org>
Auto-Submit: Juan Antonio Navarro Pérez <perezju@chromium.org>
Cr-Commit-Position: refs/heads/master@{#685376}
parent 9c06d18f
......@@ -14,9 +14,9 @@ from core import results_processor
from telemetry import command_line
def main(config):
def main(config, args=None):
options = command_line.ParseArgs(
environment=config,
environment=config, args=args,
results_arg_parser=results_processor.ArgumentParser())
results_processor.ProcessOptions(options)
run_return_code = command_line.RunCommand(options)
......
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import unittest
import mock
from core import benchmark_runner
def _FakeParseArgs(environment, args, results_arg_parser):
del environment # Unused.
options, _ = results_arg_parser.parse_known_args(args)
return options
class BenchmarkRunnerUnittest(unittest.TestCase):
def testMain_returnCode(self):
"""Test that benchmark_runner.main() respects return code from Telemetry."""
# TODO(crbug.com/985712): Ideally we should write a more "integration" kind
# of test, where we don't mock out the Telemetry command line. This is
# hard to do now, however, because we need a way to convert the browser
# selection done by the test runner, back to a suitable --browser arg for
# the command line below. Namely, we need an equivalent of
# options_for_unittests.GetCopy() that returns a list of string args
# rather than the parsed options object.
config = mock.Mock()
with mock.patch('core.benchmark_runner.command_line') as telemetry_cli:
telemetry_cli.ParseArgs.side_effect = _FakeParseArgs
telemetry_cli.RunCommand.return_value = 42
# Note: For now we pass `--output-format none` and a non-existent output
# dir to prevent the results processor from processing any results.
return_code = benchmark_runner.main(config, [
'run', 'some.benchmark', '--browser', 'stable',
'--output-dir', '/does/not/exist', '--output-format', 'none'])
self.assertEqual(return_code, 42)
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