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
3 # found in the LICENSE file.
10 from telemetry
import benchmark
as benchmark_module
11 from telemetry
.core
import browser_options
12 from telemetry
.core
import discover
13 from telemetry
.page
import page_test
14 from telemetry
.unittest_util
import options_for_unittests
15 from telemetry
.util
import classes
16 from telemetry
.web_perf
import timeline_based_measurement
19 def _GetAllPossiblePageTestInstances():
20 page_test_instances
= []
21 measurements_dir
= os
.path
.dirname(__file__
)
22 top_level_dir
= os
.path
.dirname(measurements_dir
)
23 benchmarks_dir
= os
.path
.join(top_level_dir
, 'benchmarks')
25 # Get all page test instances from measurement classes that are directly
27 all_measurement_classes
= discover
.DiscoverClasses(
28 measurements_dir
, top_level_dir
, page_test
.PageTest
,
29 index_by_class_name
=True).values()
30 for measurement_class
in all_measurement_classes
:
31 if classes
.IsDirectlyConstructable(measurement_class
):
32 page_test_instances
.append(measurement_class())
34 all_benchmarks_classes
= discover
.DiscoverClasses(
35 benchmarks_dir
, top_level_dir
, benchmark_module
.Benchmark
).values()
37 # Get all page test instances from defined benchmarks.
38 # Note: since this depends on the command line options, there is no guaranteed
39 # that this will generate all possible page test instances but it's worth
40 # enough for smoke test purpose.
41 for benchmark_class
in all_benchmarks_classes
:
42 options
= options_for_unittests
.GetCopy()
43 parser
= optparse
.OptionParser()
44 browser_options
.BrowserOptions
.AddCommandLineArgs(parser
)
46 benchmark_class
.AddCommandLineArgs(parser
)
47 benchmark_module
.AddCommandLineArgs(parser
)
48 benchmark_class
.SetArgumentDefaults(parser
)
50 logging
.error('Exception raised when processing benchmark %s'
53 options
.MergeDefaultValues(parser
.get_default_values())
54 pt
= benchmark_class().CreatePageTest(options
)
55 if not isinstance(pt
, timeline_based_measurement
.TimelineBasedMeasurement
):
56 page_test_instances
.append(pt
)
58 return page_test_instances
61 class MeasurementSmokeTest(unittest
.TestCase
):
62 # Simple smoke test to make sure that all page_test are constructible.
63 def testAllMeasurementInstance(self
):
64 _GetAllPossiblePageTestInstances()