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.
4 """Measurement smoke test to make sure that no new action_name_to_run is
12 from telemetry
import benchmark
as benchmark_module
13 from telemetry
.core
import discover
14 from telemetry
.page
import page_test
15 from telemetry
.unittest_util
import options_for_unittests
16 from telemetry
.util
import classes
17 from telemetry
.web_perf
import timeline_based_measurement
20 def _GetAllPossiblePageTestInstances():
21 page_test_instances
= []
22 measurements_dir
= os
.path
.dirname(__file__
)
23 top_level_dir
= os
.path
.dirname(measurements_dir
)
24 benchmarks_dir
= os
.path
.join(top_level_dir
, 'benchmarks')
26 # Get all page test instances from measurement classes that are directly
28 all_measurement_classes
= discover
.DiscoverClasses(
29 measurements_dir
, top_level_dir
, page_test
.PageTest
,
30 index_by_class_name
=True).values()
31 for measurement_class
in all_measurement_classes
:
32 if classes
.IsDirectlyConstructable(measurement_class
):
33 page_test_instances
.append(measurement_class())
35 all_benchmarks_classes
= discover
.DiscoverClasses(
36 benchmarks_dir
, top_level_dir
, benchmark_module
.Benchmark
).values()
38 # Get all page test instances from defined benchmarks.
39 # Note: since this depends on the command line options, there is no guaranteed
40 # that this will generate all possible page test instances but it's worth
41 # enough for smoke test purpose.
42 for benchmark_class
in all_benchmarks_classes
:
43 options
= options_for_unittests
.GetCopy()
44 parser
= optparse
.OptionParser()
45 benchmark_class
.AddCommandLineArgs(parser
)
46 benchmark_module
.AddCommandLineArgs(parser
)
47 benchmark_class
.SetArgumentDefaults(parser
)
48 options
.MergeDefaultValues(parser
.get_default_values())
49 pt
= benchmark_class().CreatePageTest(options
)
50 if not isinstance(pt
, timeline_based_measurement
.TimelineBasedMeasurement
):
51 page_test_instances
.append(pt
)
53 return page_test_instances
56 class MeasurementSmokeTest(unittest
.TestCase
):
57 # Simple smoke test to make sure that all page_test are constructible.
58 def testAllMeasurementInstance(self
):
59 _GetAllPossiblePageTestInstances()