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 discover
12 from telemetry
.internal
.browser
import browser_options
13 from telemetry
.page
import page_test
14 from telemetry
.testing
import options_for_unittests
15 from telemetry
.web_perf
import timeline_based_measurement
18 def _GetAllPossiblePageTestInstances():
19 page_test_instances
= []
20 measurements_dir
= os
.path
.dirname(__file__
)
21 top_level_dir
= os
.path
.dirname(measurements_dir
)
22 benchmarks_dir
= os
.path
.join(top_level_dir
, 'benchmarks')
24 # Get all page test instances from measurement classes that are directly
26 all_measurement_classes
= discover
.DiscoverClasses(
27 measurements_dir
, top_level_dir
, page_test
.PageTest
,
28 index_by_class_name
=True, directly_constructable
=True).values()
29 for measurement_class
in all_measurement_classes
:
30 page_test_instances
.append(measurement_class())
32 all_benchmarks_classes
= discover
.DiscoverClasses(
33 benchmarks_dir
, top_level_dir
, benchmark_module
.Benchmark
).values()
35 # Get all page test instances from defined benchmarks.
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
38 # enough for smoke test purpose.
39 for benchmark_class
in all_benchmarks_classes
:
40 options
= options_for_unittests
.GetCopy()
41 parser
= optparse
.OptionParser()
42 browser_options
.BrowserOptions
.AddCommandLineArgs(parser
)
44 benchmark_class
.AddCommandLineArgs(parser
)
45 benchmark_module
.AddCommandLineArgs(parser
)
46 benchmark_class
.SetArgumentDefaults(parser
)
48 logging
.error('Exception raised when processing benchmark %s'
51 options
.MergeDefaultValues(parser
.get_default_values())
52 pt
= benchmark_class().CreatePageTest(options
)
53 if not isinstance(pt
, timeline_based_measurement
.TimelineBasedMeasurement
):
54 page_test_instances
.append(pt
)
56 return page_test_instances
59 class MeasurementSmokeTest(unittest
.TestCase
):
60 # Simple smoke test to make sure that all page_test are constructible.
61 def testAllMeasurementInstance(self
):
62 _GetAllPossiblePageTestInstances()