Commit f29d7834 authored by eakuefner's avatar eakuefner Committed by Commit bot

Revert of [Telemetry] Pass test_runner environment in local args instead of a...

Revert of [Telemetry] Pass test_runner environment in local args instead of a global variable (patchset #9 id:160001 of https://codereview.chromium.org/942663002/)

Reason for revert:
crbug.com/462063

Original issue's description:
> [Telemetry] Pass test_runner environment in local args instead of a global variable
>
> Also adds more fields to environment to narrow the scope of
> benchmark and user story set discovery. This should avoid problems
> with adding Python files to unrelated directories, and hides PageTests
> from external Telemetry benchmark runners like run_gpu_tests.py and
> chrome_proxy's run_benchmark.
>
> R=dtu,nednguyen,sullivan,kbr@chromium.org,bolian
> BUG=460181
> TEST=tools/perf/run_benchmark; content/test/gpu/run_gpu_tests.py; tools/chrome_proxy/run_benchmark  # All return a full and correct test list.
>
> Committed: https://crrev.com/1da5f7f70ea6dc7dd0667ea78637802c76305f5a
> Cr-Commit-Position: refs/heads/master@{#318149}

TBR=bolian@chromium.org,dtu@chromium.org,kbr@chromium.org,nednguyen@google.com,sullivan@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=460181

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

Cr-Commit-Position: refs/heads/master@{#318175}
parent 5b1c02ff
...@@ -12,6 +12,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__), ...@@ -12,6 +12,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__),
os.pardir, os.pardir, os.pardir, 'tools', 'telemetry')) os.pardir, os.pardir, os.pardir, 'tools', 'telemetry'))
from telemetry import benchmark_runner from telemetry import benchmark_runner
from telemetry.core import environment
def _LaunchDBus(): def _LaunchDBus():
...@@ -84,14 +85,12 @@ def _ShutdownDBus(): ...@@ -84,14 +85,12 @@ def _ShutdownDBus():
if __name__ == '__main__': if __name__ == '__main__':
top_level_dir = os.path.dirname(os.path.realpath(__file__)) base_dir = os.path.dirname(os.path.realpath(__file__))
environment = benchmark_runner.Environment( benchmark_runner.config = environment.Environment([base_dir])
top_level_dir=top_level_dir,
benchmark_dirs=[os.path.join(top_level_dir, 'gpu_tests')])
did_launch_dbus = _LaunchDBus() did_launch_dbus = _LaunchDBus()
try: try:
retcode = benchmark_runner.main(environment) retcode = benchmark_runner.main()
finally: finally:
if did_launch_dbus: if did_launch_dbus:
_ShutdownDBus() _ShutdownDBus()
......
...@@ -10,11 +10,10 @@ sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, 'telemetry')) ...@@ -10,11 +10,10 @@ sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, 'telemetry'))
sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, 'perf')) sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, 'perf'))
from telemetry import benchmark_runner from telemetry import benchmark_runner
from telemetry.core import environment
if __name__ == '__main__': if __name__ == '__main__':
top_level_dir = os.path.dirname(os.path.realpath(__file__)) base_dir = os.path.dirname(os.path.realpath(__file__))
environment = benchmark_runner.Environment( benchmark_runner.config = environment.Environment([base_dir])
top_level_dir=top_level_dir, sys.exit(benchmark_runner.main())
benchmark_dirs=[os.path.join(top_level_dir, 'integration_tests')])
sys.exit(benchmark_runner.main(environment))
...@@ -9,12 +9,10 @@ import sys ...@@ -9,12 +9,10 @@ import sys
sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, 'telemetry')) sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, 'telemetry'))
from telemetry import benchmark_runner from telemetry import benchmark_runner
from telemetry.core import environment
if __name__ == '__main__': if __name__ == '__main__':
top_level_dir = os.path.dirname(os.path.realpath(__file__)) base_dir = os.path.dirname(os.path.realpath(__file__))
benchmark_runner.config = environment.Environment([base_dir])
environment = benchmark_runner.Environment( sys.exit(benchmark_runner.main())
top_level_dir=top_level_dir,
benchmark_dirs=[os.path.join(top_level_dir, 'benchmarks')])
sys.exit(benchmark_runner.main(environment))
...@@ -19,44 +19,11 @@ from telemetry.core import browser_finder ...@@ -19,44 +19,11 @@ from telemetry.core import browser_finder
from telemetry.core import browser_options from telemetry.core import browser_options
from telemetry.core import command_line from telemetry.core import command_line
from telemetry.core import discover from telemetry.core import discover
from telemetry.core import environment
from telemetry.core import util from telemetry.core import util
from telemetry.util import find_dependencies from telemetry.util import find_dependencies
class Environment(object):
"""Contains information about the benchmark runtime environment.
Attributes:
top_level_dir: A dir that contains benchmark, page test, and/or user story
set dirs and associated artifacts.
benchmark_dirs: A list of dirs containing benchmarks.
benchmark_aliases: A dict of name:alias string pairs to be matched against
exactly during benchmark selection.
"""
def __init__(self, top_level_dir, benchmark_dirs=None,
benchmark_aliases=None):
self._top_level_dir = top_level_dir
self._benchmark_dirs = benchmark_dirs or []
self._benchmark_aliases = benchmark_aliases or dict()
if benchmark_aliases:
self._benchmark_aliases = benchmark_aliases
else:
self._benchmark_aliases = {}
@property
def top_level_dir(self):
return self._top_level_dir
@property
def benchmark_dirs(self):
return self._benchmark_dirs
@property
def benchmark_aliases(self):
return self._benchmark_aliases
class Help(command_line.OptparseCommand): class Help(command_line.OptparseCommand):
"""Display help information about a command""" """Display help information about a command"""
...@@ -94,17 +61,17 @@ class List(command_line.OptparseCommand): ...@@ -94,17 +61,17 @@ class List(command_line.OptparseCommand):
return parser return parser
@classmethod @classmethod
def AddCommandLineArgs(cls, parser, _): def AddCommandLineArgs(cls, parser):
parser.add_option('-j', '--json-output-file', type='string') parser.add_option('-j', '--json-output-file', type='string')
parser.add_option('-n', '--num-shards', type='int', default=1) parser.add_option('-n', '--num-shards', type='int', default=1)
@classmethod @classmethod
def ProcessCommandLineArgs(cls, parser, args, environment): def ProcessCommandLineArgs(cls, parser, args):
if not args.positional_args: if not args.positional_args:
args.benchmarks = _Benchmarks(environment) args.benchmarks = _Benchmarks()
elif len(args.positional_args) == 1: elif len(args.positional_args) == 1:
args.benchmarks = _MatchBenchmarkName(args.positional_args[0], args.benchmarks = _MatchBenchmarkName(args.positional_args[0],
environment, exact_matches=False) exact_matches=False)
else: else:
parser.error('Must provide at most one benchmark name.') parser.error('Must provide at most one benchmark name.')
...@@ -138,13 +105,13 @@ class Run(command_line.OptparseCommand): ...@@ -138,13 +105,13 @@ class Run(command_line.OptparseCommand):
return parser return parser
@classmethod @classmethod
def AddCommandLineArgs(cls, parser, environment): def AddCommandLineArgs(cls, parser):
benchmark.AddCommandLineArgs(parser) benchmark.AddCommandLineArgs(parser)
# Allow benchmarks to add their own command line options. # Allow benchmarks to add their own command line options.
matching_benchmarks = [] matching_benchmarks = []
for arg in sys.argv[1:]: for arg in sys.argv[1:]:
matching_benchmarks += _MatchBenchmarkName(arg, environment) matching_benchmarks += _MatchBenchmarkName(arg)
if matching_benchmarks: if matching_benchmarks:
# TODO(dtu): After move to argparse, add command-line args for all # TODO(dtu): After move to argparse, add command-line args for all
...@@ -156,19 +123,19 @@ class Run(command_line.OptparseCommand): ...@@ -156,19 +123,19 @@ class Run(command_line.OptparseCommand):
matching_benchmark.SetArgumentDefaults(parser) matching_benchmark.SetArgumentDefaults(parser)
@classmethod @classmethod
def ProcessCommandLineArgs(cls, parser, args, environment): def ProcessCommandLineArgs(cls, parser, args):
if not args.positional_args: if not args.positional_args:
possible_browser = ( possible_browser = (
browser_finder.FindBrowser(args) if args.browser_type else None) browser_finder.FindBrowser(args) if args.browser_type else None)
_PrintBenchmarkList(_Benchmarks(environment), possible_browser) _PrintBenchmarkList(_Benchmarks(), possible_browser, sys.stderr)
sys.exit(-1) sys.exit(-1)
input_benchmark_name = args.positional_args[0] input_benchmark_name = args.positional_args[0]
matching_benchmarks = _MatchBenchmarkName(input_benchmark_name, environment) matching_benchmarks = _MatchBenchmarkName(input_benchmark_name)
if not matching_benchmarks: if not matching_benchmarks:
print >> sys.stderr, 'No benchmark named "%s".' % input_benchmark_name print >> sys.stderr, 'No benchmark named "%s".' % input_benchmark_name
print >> sys.stderr print >> sys.stderr
_PrintBenchmarkList(_Benchmarks(environment), None, sys.stderr) _PrintBenchmarkList(_Benchmarks(), None, sys.stderr)
sys.exit(-1) sys.exit(-1)
if len(matching_benchmarks) > 1: if len(matching_benchmarks) > 1:
...@@ -213,16 +180,15 @@ def _MatchingCommands(string): ...@@ -213,16 +180,15 @@ def _MatchingCommands(string):
if command.Name().startswith(string)] if command.Name().startswith(string)]
@decorators.Cache @decorators.Cache
def _Benchmarks(environment): def _Benchmarks():
benchmarks = [] benchmarks = []
for search_dir in environment.benchmark_dirs: for base_dir in config.base_paths:
benchmarks += discover.DiscoverClasses(search_dir, benchmarks += discover.DiscoverClasses(base_dir, base_dir,
environment.top_level_dir,
benchmark.Benchmark, benchmark.Benchmark,
index_by_class_name=True).values() index_by_class_name=True).values()
return benchmarks return benchmarks
def _MatchBenchmarkName(input_benchmark_name, environment, exact_matches=True): def _MatchBenchmarkName(input_benchmark_name, exact_matches=True):
def _Matches(input_string, search_string): def _Matches(input_string, search_string):
if search_string.startswith(input_string): if search_string.startswith(input_string):
return True return True
...@@ -234,18 +200,18 @@ def _MatchBenchmarkName(input_benchmark_name, environment, exact_matches=True): ...@@ -234,18 +200,18 @@ def _MatchBenchmarkName(input_benchmark_name, environment, exact_matches=True):
# Exact matching. # Exact matching.
if exact_matches: if exact_matches:
# Don't add aliases to search dict, only allow exact matching for them. # Don't add aliases to search dict, only allow exact matching for them.
if input_benchmark_name in environment.benchmark_aliases: if input_benchmark_name in config.benchmark_aliases:
exact_match = environment.benchmark_aliases[input_benchmark_name] exact_match = config.benchmark_aliases[input_benchmark_name]
else: else:
exact_match = input_benchmark_name exact_match = input_benchmark_name
for benchmark_class in _Benchmarks(environment): for benchmark_class in _Benchmarks():
if exact_match == benchmark_class.Name(): if exact_match == benchmark_class.Name():
return [benchmark_class] return [benchmark_class]
return [] return []
# Fuzzy matching. # Fuzzy matching.
return [benchmark_class for benchmark_class in _Benchmarks(environment) return [benchmark_class for benchmark_class in _Benchmarks()
if _Matches(input_benchmark_name, benchmark_class.Name())] if _Matches(input_benchmark_name, benchmark_class.Name())]
...@@ -344,7 +310,10 @@ def _PrintBenchmarkList(benchmarks, possible_browser, output_pipe=sys.stdout): ...@@ -344,7 +310,10 @@ def _PrintBenchmarkList(benchmarks, possible_browser, output_pipe=sys.stdout):
print >> output_pipe print >> output_pipe
def main(environment): config = environment.Environment([util.GetBaseDir()])
def main():
# Get the command name from the command line. # Get the command name from the command line.
if len(sys.argv) > 1 and sys.argv[1] == '--help': if len(sys.argv) > 1 and sys.argv[1] == '--help':
sys.argv[1] = 'help' sys.argv[1] = 'help'
...@@ -371,10 +340,10 @@ def main(environment): ...@@ -371,10 +340,10 @@ def main(environment):
# Parse and run the command. # Parse and run the command.
parser = command.CreateParser() parser = command.CreateParser()
command.AddCommandLineArgs(parser, environment) command.AddCommandLineArgs(parser)
options, args = parser.parse_args() options, args = parser.parse_args()
if commands: if commands:
args = args[1:] args = args[1:]
options.positional_args = args options.positional_args = args
command.ProcessCommandLineArgs(parser, options, environment) command.ProcessCommandLineArgs(parser, options)
return command().Run(options) return command().Run(options)
...@@ -64,16 +64,6 @@ class OptparseCommand(Command): ...@@ -64,16 +64,6 @@ class OptparseCommand(Command):
return optparse.OptionParser('%%prog %s %s' % (cls.Name(), cls.usage), return optparse.OptionParser('%%prog %s %s' % (cls.Name(), cls.usage),
description=cls.Description()) description=cls.Description())
@classmethod
def AddCommandLineArgs(cls, parser, environment):
# pylint: disable=arguments-differ
pass
@classmethod
def ProcessCommandLineArgs(cls, parser, args, environment):
# pylint: disable=arguments-differ
pass
def Run(self, args): def Run(self, args):
raise NotImplementedError() raise NotImplementedError()
......
# Copyright 2014 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.
class Environment(object):
def __init__(self, base_paths, benchmark_aliases=None):
self._base_paths = base_paths
if benchmark_aliases:
self._benchmark_aliases = benchmark_aliases
else:
self._benchmark_aliases = {}
@property
def base_paths(self):
return self._base_paths
@property
def benchmark_aliases(self):
return self._benchmark_aliases
...@@ -35,7 +35,7 @@ class RunTestsCommand(command_line.OptparseCommand): ...@@ -35,7 +35,7 @@ class RunTestsCommand(command_line.OptparseCommand):
return parser return parser
@classmethod @classmethod
def AddCommandLineArgs(cls, parser, _): def AddCommandLineArgs(cls, parser):
parser.add_option('--repeat-count', type='int', default=1, parser.add_option('--repeat-count', type='int', default=1,
help='Repeats each a provided number of times.') help='Repeats each a provided number of times.')
parser.add_option('-d', '--also-run-disabled-tests', parser.add_option('-d', '--also-run-disabled-tests',
...@@ -55,7 +55,7 @@ class RunTestsCommand(command_line.OptparseCommand): ...@@ -55,7 +55,7 @@ class RunTestsCommand(command_line.OptparseCommand):
reporting=True) reporting=True)
@classmethod @classmethod
def ProcessCommandLineArgs(cls, parser, args, _): def ProcessCommandLineArgs(cls, parser, args):
# We retry failures by default unless we're running a list of tests # We retry failures by default unless we're running a list of tests
# explicitly. # explicitly.
if not args.retry_limit and not args.positional_args: if not args.retry_limit and not args.positional_args:
...@@ -75,10 +75,10 @@ class RunTestsCommand(command_line.OptparseCommand): ...@@ -75,10 +75,10 @@ class RunTestsCommand(command_line.OptparseCommand):
def main(cls, args=None, stream=None): # pylint: disable=W0221 def main(cls, args=None, stream=None): # pylint: disable=W0221
# We override the superclass so that we can hook in the 'stream' arg. # We override the superclass so that we can hook in the 'stream' arg.
parser = cls.CreateParser() parser = cls.CreateParser()
cls.AddCommandLineArgs(parser, None) cls.AddCommandLineArgs(parser)
options, positional_args = parser.parse_args(args) options, positional_args = parser.parse_args(args)
options.positional_args = positional_args options.positional_args = positional_args
cls.ProcessCommandLineArgs(parser, options, None) cls.ProcessCommandLineArgs(parser, options)
obj = cls() obj = cls()
if stream is not None: if stream is not None:
......
...@@ -227,7 +227,7 @@ class FindDependenciesCommand(command_line.OptparseCommand): ...@@ -227,7 +227,7 @@ class FindDependenciesCommand(command_line.OptparseCommand):
"""Prints all dependencies""" """Prints all dependencies"""
@classmethod @classmethod
def AddCommandLineArgs(cls, parser, _): def AddCommandLineArgs(cls, parser):
parser.add_option( parser.add_option(
'-v', '--verbose', action='count', dest='verbosity', '-v', '--verbose', action='count', dest='verbosity',
help='Increase verbosity level (repeat as needed).') help='Increase verbosity level (repeat as needed).')
...@@ -245,7 +245,7 @@ class FindDependenciesCommand(command_line.OptparseCommand): ...@@ -245,7 +245,7 @@ class FindDependenciesCommand(command_line.OptparseCommand):
help='Store files in a zip archive at ZIP.') help='Store files in a zip archive at ZIP.')
@classmethod @classmethod
def ProcessCommandLineArgs(cls, parser, args, _): def ProcessCommandLineArgs(cls, parser, args):
if args.verbosity >= 2: if args.verbosity >= 2:
logging.getLogger().setLevel(logging.DEBUG) logging.getLogger().setLevel(logging.DEBUG)
elif args.verbosity: elif args.verbosity:
......
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