def FindPageSetDependencies(base_dir): logging.info('Finding page sets in %s' % base_dir) # Add base_dir to path so our imports relative to base_dir will work. sys.path.append(base_dir) tests = classes_util.DiscoverClasses(base_dir, base_dir, benchmark.Benchmark) for test_class in tests: test_obj = test_class() # Ensure the test's default options are set if needed. parser = optparse.OptionParser() test_obj.AddCommandLineArgs(parser, None) options = optparse.Values() for k, v in parser.get_default_values().__dict__.iteritems(): options.ensure_value(k, v) # Page set paths are relative to their runner script, not relative to us. path.GetBaseDir = lambda: base_dir # TODO: Loading the page set will automatically download its Cloud Storage # deps. This is really expensive, and we don't want to do this by default. page_set = test_obj.CreatePageSet(options) # Add all of its serving_dirs as dependencies. for serving_dir in page_set.serving_dirs: yield serving_dir
def _Benchmarks(environment): benchmarks = [] for search_dir in environment.benchmark_dirs: benchmarks += classes_util.DiscoverClasses(search_dir, environment.top_level_dir, benchmark.Benchmark) return benchmarks
def _MatchPageSetName(page_set_name, page_set_base_dir): page_sets = [] page_sets += classes_util.DiscoverClasses(page_set_base_dir, page_set_base_dir, page_set.PageSet) for p in page_sets: if page_set_name == p.Name(): return p return None
def _GetAllPossiblePageTestInstances(): page_test_instances = [] measurements_dir = os.path.dirname(__file__) top_level_dir = os.path.dirname(measurements_dir) benchmarks_dir = os.path.join(top_level_dir, 'benchmarks') # Get all page test instances from measurement classes that are directly # constructable all_measurement_classes = classes_util.DiscoverClasses( measurements_dir, top_level_dir, page_test.PageTest, directly_constructable=True) for measurement_class in all_measurement_classes: page_test_instances.append(measurement_class()) all_benchmarks_classes = classes_util.DiscoverClasses( benchmarks_dir, top_level_dir, benchmark_module.Benchmark) # Get all page test instances from defined benchmarks. # Note: since this depends on the command line options, there is no guaranteed # that this will generate all possible page test instances but it's worth # enough for smoke test purpose. for benchmark_class in all_benchmarks_classes: options = options_for_unittests.GetCopy() parser = optparse.OptionParser() browser_options.BrowserOptions.AddCommandLineArgs(parser) try: benchmark_class.AddCommandLineArgs(parser) benchmark_module.AddCommandLineArgs(parser) benchmark_class.SetArgumentDefaults(parser) except Exception: logging.error('Exception raised when processing benchmark %s' % benchmark_class) raise options.MergeDefaultValues(parser.get_default_values()) pt = benchmark_class().CreatePageTest(options) if not isinstance(pt, timeline_based_measurement.TimelineBasedMeasurement): page_test_instances.append(pt) return page_test_instances
def RunSmokeTest(self, story_sets_dir, top_level_dir): """Run smoke test on all story sets in story_sets_dir. Subclass of StorySetSmokeTest is supposed to call this in some test method to run smoke test. """ # We can't test page sets that aren't directly constructable since we # don't know what arguments to put for the constructor. story_sets = classes_util.DiscoverClasses(story_sets_dir, top_level_dir, story_module.StorySet, directly_constructable=True) for story_set_class in story_sets: story_set = story_set_class() logging.info('Testing %s', story_set.file_path) self.CheckArchive(story_set) self.CheckCredentials(story_set) self.CheckAttributes(story_set) self.CheckSharedStates(story_set)
def _IterAllPlatformBackendClasses(): platform_dir = os.path.dirname(os.path.realpath(__file__)) return classes_util.DiscoverClasses( platform_dir, util.GetTelemetryDir(), platform_backend_module.PlatformBackend)
# Copyright (c) 2012 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 os import sys from telemetry.util import classes_util from telemetry.page import page_set # Import all submodules' PageSet classes. start_dir = os.path.dirname(os.path.abspath(__file__)) top_level_dir = os.path.dirname(start_dir) base_class = page_set.PageSet for cls in classes_util.DiscoverClasses(start_dir, top_level_dir, base_class): setattr(sys.modules[__name__], cls.__name__, cls)
def _IterAllTracingAgentClasses(): tracing_agent_dir = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'tracing_agent') return classes_util.DiscoverClasses(tracing_agent_dir, util.GetTelemetryDir(), tracing_agent.TracingAgent)
def _DiscoverProfilers(): profiler_dir = os.path.dirname(__file__) return classes_util.DiscoverClasses(profiler_dir, util.GetTelemetryDir(), profiler.Profiler)
def _GetAllPerfBenchmarks(): return classes_util.DiscoverClasses(_GetPerfDir('benchmarks'), _GetPerfDir(), benchmark_module.Benchmark)