• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python2
2
3"""
4This file generates all telemetry_Benchmarks control files from a master list.
5"""
6
7from datetime import datetime
8import os
9import re
10
11# This test list is a subset of telemetry benchmark tests. The full list can be
12# obtained by executing
13# /build/${BOARD}/usr/local/telemetry/src/tools/perf/list_benchmarks
14
15# PLEASE READ THIS:
16
17# PERF_TESTS: these tests run on each build: tot, tot-1, tot-2 and expensive to
18# run.
19
20# PERF_DAILY_RUN_TESTS: these tests run on a nightly build: tot. If you are
21# trying to gain confidence for a new test, adding your test in this list is a
22# good start.
23
24# For adding a new test to any of these lists, please add rohitbm, lafeenstra,
25# haddowk in the change.
26
27PERF_PER_BUILD_TESTS = (
28    'cros_ui_smoothness',
29    'jetstream',
30    'kraken',
31    'loading.desktop',
32    'octane',
33    'rendering.desktop',
34    'speedometer',
35    'speedometer2',
36)
37
38PERF_DAILY_RUN_TESTS = (
39    'blink_perf.image_decoder',
40    'cros_tab_switching.typical_24',
41    'dromaeo',
42    'media.desktop',
43    'memory.desktop',
44    'smoothness.tough_pinch_zoom_cases',
45    'system_health.memory_desktop',
46    'webrtc',
47)
48
49PERF_WEEKLY_RUN_TESTS = (
50)
51
52ALL_TESTS = (PERF_PER_BUILD_TESTS +
53             PERF_DAILY_RUN_TESTS +
54             PERF_WEEKLY_RUN_TESTS)
55
56EXTRA_ARGS_MAP = {
57    'loading.desktop': '--story-tag-filter=typical',
58    'rendering.desktop': '--story-tag-filter=top_real_world_desktop',
59    'system_health.memory_desktop': '--pageset-repeat=1',
60}
61
62DEFAULT_YEAR = str(datetime.now().year)
63
64DEFAULT_AUTHOR = 'Chrome OS Team'
65
66CONTROLFILE_TEMPLATE = (
67"""# Copyright {year} The Chromium OS Authors. All rights reserved.
68# Use of this source code is governed by a BSD-style license that can be
69# found in the LICENSE file.
70
71# Do not edit this file! It was created by generate_controlfiles.py.
72
73from autotest_lib.client.common_lib import utils
74
75AUTHOR = '{author}'
76NAME = 'telemetry_Benchmarks.{test}'
77{attributes}
78TIME = 'LONG'
79TEST_CATEGORY = 'Benchmark'
80TEST_CLASS = 'performance'
81TEST_TYPE = 'server'
82
83DOC = '''
84This server side test suite executes the Telemetry Benchmark:
85{test}
86This is part of Chrome for Chrome OS performance testing.
87
88Pass local=True to run with local telemetry and no AFE server.
89'''
90
91def run_benchmark(machine):
92    host = hosts.create_host(machine)
93    dargs = utils.args_to_dict(args)
94    dargs['extra_args'] = '{extra_args}'.split()
95    job.run_test('telemetry_Benchmarks', host=host,
96                 benchmark='{test}',
97                 tag='{test}',
98                 args=dargs)
99
100parallel_simple(run_benchmark, machines)""")
101
102
103def _get_suite(test):
104    if test in PERF_PER_BUILD_TESTS:
105        return 'ATTRIBUTES = \'suite:crosbolt_perf_perbuild\''
106    elif test in PERF_DAILY_RUN_TESTS:
107        return 'ATTRIBUTES = \'suite:crosbolt_perf_nightly\''
108    elif test in PERF_WEEKLY_RUN_TESTS:
109        return 'ATTRIBUTES = \'suite:crosbolt_perf_weekly\''
110    return ''
111
112
113def get_existing_fields(filename):
114    """Returns the existing copyright year and author of the control file."""
115    if not os.path.isfile(filename):
116        return (DEFAULT_YEAR, DEFAULT_AUTHOR)
117
118    copyright_year = DEFAULT_YEAR
119    author = DEFAULT_AUTHOR
120    copyright_pattern = re.compile(
121            '# Copyright (\d+) The Chromium OS Authors.')
122    author_pattern = re.compile("AUTHOR = '(.+)'")
123    with open(filename) as f:
124        for line in f:
125            match_year = copyright_pattern.match(line)
126            if match_year:
127                copyright_year = match_year.group(1)
128            match_author = author_pattern.match(line)
129            if match_author:
130                author = match_author.group(1)
131    return (copyright_year, author)
132
133
134def generate_control(test):
135    """Generates control file from the template."""
136    filename = 'control.%s' % test
137    copyright_year, author = get_existing_fields(filename)
138    extra_args = EXTRA_ARGS_MAP.get(test, '')
139
140    with open(filename, 'w+') as f:
141        content = CONTROLFILE_TEMPLATE.format(
142                attributes=_get_suite(test),
143                author=author,
144                extra_args=extra_args,
145                test=test,
146                year=copyright_year)
147        f.write(content)
148
149
150def check_unmanaged_control_files():
151    """Prints warning if there is unmanaged control file."""
152    for filename in os.listdir('.'):
153        if not filename.startswith('control.'):
154            continue
155        test = filename[len('control.'):]
156        if test not in ALL_TESTS:
157            print 'warning, unmanaged control file:', test
158
159
160def main():
161    """The main function."""
162    for test in ALL_TESTS:
163        generate_control(test)
164    check_unmanaged_control_files()
165
166
167if __name__ == "__main__":
168    main()
169