| OLD | NEW | 
|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be | 
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. | 
| 4 | 4 | 
| 5 import logging | 5 import logging | 
| 6 import optparse | 6 import optparse | 
| 7 import os | 7 import os | 
| 8 import unittest | 8 import unittest | 
| 9 | 9 | 
| 10 from telemetry import benchmark as benchmark_module | 10 from telemetry import benchmark as benchmark_module | 
|  | 11 from telemetry.core import discover | 
| 11 from telemetry.internal.browser import browser_options | 12 from telemetry.internal.browser import browser_options | 
| 12 from telemetry.page import page_test | 13 from telemetry.page import page_test | 
| 13 from telemetry.testing import options_for_unittests | 14 from telemetry.testing import options_for_unittests | 
| 14 from telemetry.util import classes_util |  | 
| 15 from telemetry.web_perf import timeline_based_measurement | 15 from telemetry.web_perf import timeline_based_measurement | 
| 16 | 16 | 
| 17 | 17 | 
| 18 def _GetAllPossiblePageTestInstances(): | 18 def _GetAllPossiblePageTestInstances(): | 
| 19   page_test_instances = [] | 19   page_test_instances = [] | 
| 20   measurements_dir = os.path.dirname(__file__) | 20   measurements_dir = os.path.dirname(__file__) | 
| 21   top_level_dir = os.path.dirname(measurements_dir) | 21   top_level_dir = os.path.dirname(measurements_dir) | 
| 22   benchmarks_dir = os.path.join(top_level_dir, 'benchmarks') | 22   benchmarks_dir = os.path.join(top_level_dir, 'benchmarks') | 
| 23 | 23 | 
| 24   # Get all page test instances from measurement classes that are directly | 24   # Get all page test instances from measurement classes that are directly | 
| 25   # constructable | 25   # constructable | 
| 26   all_measurement_classes = classes_util.DiscoverClasses( | 26   all_measurement_classes = discover.DiscoverClasses( | 
| 27       measurements_dir, top_level_dir, page_test.PageTest, | 27       measurements_dir, top_level_dir, page_test.PageTest, | 
| 28       directly_constructable=True) | 28       index_by_class_name=True, directly_constructable=True).values() | 
| 29   for measurement_class in all_measurement_classes: | 29   for measurement_class in all_measurement_classes: | 
| 30     page_test_instances.append(measurement_class()) | 30     page_test_instances.append(measurement_class()) | 
| 31 | 31 | 
| 32   all_benchmarks_classes = classes_util.DiscoverClasses( | 32   all_benchmarks_classes = discover.DiscoverClasses( | 
| 33       benchmarks_dir, top_level_dir, benchmark_module.Benchmark) | 33       benchmarks_dir, top_level_dir, benchmark_module.Benchmark).values() | 
| 34 | 34 | 
| 35   # Get all page test instances from defined benchmarks. | 35   # Get all page test instances from defined benchmarks. | 
| 36   # Note: since this depends on the command line options, there is no guaranteed | 36   # Note: since this depends on the command line options, there is no guaranteed | 
| 37   # that this will generate all possible page test instances but it's worth | 37   # that this will generate all possible page test instances but it's worth | 
| 38   # enough for smoke test purpose. | 38   # enough for smoke test purpose. | 
| 39   for benchmark_class in all_benchmarks_classes: | 39   for benchmark_class in all_benchmarks_classes: | 
| 40     options = options_for_unittests.GetCopy() | 40     options = options_for_unittests.GetCopy() | 
| 41     parser = optparse.OptionParser() | 41     parser = optparse.OptionParser() | 
| 42     browser_options.BrowserOptions.AddCommandLineArgs(parser) | 42     browser_options.BrowserOptions.AddCommandLineArgs(parser) | 
| 43     try: | 43     try: | 
| 44       benchmark_class.AddCommandLineArgs(parser) | 44       benchmark_class.AddCommandLineArgs(parser) | 
| 45       benchmark_module.AddCommandLineArgs(parser) | 45       benchmark_module.AddCommandLineArgs(parser) | 
| 46       benchmark_class.SetArgumentDefaults(parser) | 46       benchmark_class.SetArgumentDefaults(parser) | 
| 47     except Exception: | 47     except Exception: | 
| 48       logging.error('Exception raised when processing benchmark %s' | 48       logging.error('Exception raised when processing benchmark %s' | 
| 49           % benchmark_class) | 49           % benchmark_class) | 
| 50       raise | 50       raise | 
| 51     options.MergeDefaultValues(parser.get_default_values()) | 51     options.MergeDefaultValues(parser.get_default_values()) | 
| 52     pt = benchmark_class().CreatePageTest(options) | 52     pt = benchmark_class().CreatePageTest(options) | 
| 53     if not isinstance(pt, timeline_based_measurement.TimelineBasedMeasurement): | 53     if not isinstance(pt, timeline_based_measurement.TimelineBasedMeasurement): | 
| 54       page_test_instances.append(pt) | 54       page_test_instances.append(pt) | 
| 55 | 55 | 
| 56   return page_test_instances | 56   return page_test_instances | 
| 57 | 57 | 
| 58 | 58 | 
| 59 class MeasurementSmokeTest(unittest.TestCase): | 59 class MeasurementSmokeTest(unittest.TestCase): | 
| 60   # Simple smoke test to make sure that all page_test are constructible. | 60   # Simple smoke test to make sure that all page_test are constructible. | 
| 61   def testAllMeasurementInstance(self): | 61   def testAllMeasurementInstance(self): | 
| 62     _GetAllPossiblePageTestInstances() | 62     _GetAllPossiblePageTestInstances() | 
| OLD | NEW | 
|---|