OLD | NEW |
| (Empty) |
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 | |
5 import logging | |
6 import os | |
7 import unittest | |
8 | |
9 from telemetry import test | |
10 from telemetry.core import discover | |
11 from telemetry.page import page_measurement | |
12 from telemetry.unittest import options_for_unittests | |
13 | |
14 | |
15 class MeasurementUnitTest(unittest.TestCase): | |
16 | |
17 # TODO(achuith): Fix crbug.com/351114. | |
18 @test.Disabled('android', 'chromeos', 'win') | |
19 def testMeasurementSmoke(self): | |
20 # Run all Measurements against the first Page in the PageSet of the first | |
21 # Benchmark that uses them. | |
22 # | |
23 # Ideally this test would be comprehensive, but the above serves as a | |
24 # kind of smoke test. | |
25 measurements_dir = os.path.dirname(__file__) | |
26 top_level_dir = os.path.dirname(measurements_dir) | |
27 benchmarks_dir = os.path.join(top_level_dir, 'benchmarks') | |
28 | |
29 all_measurements = discover.DiscoverClasses( | |
30 measurements_dir, top_level_dir, page_measurement.PageMeasurement, | |
31 pattern='*.py').values() | |
32 all_benchmarks = discover.DiscoverClasses( | |
33 benchmarks_dir, top_level_dir, test.Test, pattern='*.py').values() | |
34 | |
35 for benchmark in all_benchmarks: | |
36 if benchmark.test not in all_measurements: | |
37 # If the benchmark is not in measurements, then it is not composable. | |
38 # Ideally we'd like to test these as well, but the non-composable | |
39 # benchmarks are usually long-running benchmarks. | |
40 continue | |
41 | |
42 if hasattr(benchmark, 'generated_profile_archive'): | |
43 # We'd like to test these, but don't know how yet. | |
44 continue | |
45 | |
46 # Only measure a single page so that this test cycles reasonably quickly. | |
47 benchmark.options['pageset_repeat'] = 1 | |
48 benchmark.options['page_repeat'] = 1 | |
49 | |
50 class SinglePageBenchmark(benchmark): # pylint: disable=W0232 | |
51 def CreatePageSet(self, options): | |
52 # pylint: disable=E1002 | |
53 ps = super(SinglePageBenchmark, self).CreatePageSet(options) | |
54 ps.pages = ps.pages[:1] | |
55 return ps | |
56 | |
57 logging.info('running: %s', benchmark) | |
58 | |
59 # Set the benchmark's default arguments. | |
60 options = options_for_unittests.GetCopy() | |
61 options.output_format = 'none' | |
62 parser = options.CreateParser() | |
63 | |
64 benchmark.AddCommandLineArgs(parser) | |
65 test.AddCommandLineArgs(parser) | |
66 benchmark.SetArgumentDefaults(parser) | |
67 options.MergeDefaultValues(parser.get_default_values()) | |
68 | |
69 benchmark.ProcessCommandLineArgs(None, options) | |
70 test.ProcessCommandLineArgs(None, options) | |
71 | |
72 self.assertEqual(0, SinglePageBenchmark().Run(options), | |
73 msg='Failed: %s' % benchmark) | |
OLD | NEW |